ssm框架获得实时的自增id

需求:使用MyBatis往MySQL数据库中插入一条记录后,需要返回该条记录的自增主键值。
 
方法:在mapper中指定keyProperty属性,示例如下:
Xml代码  收藏代码
useGeneratedKeys="true" keyProperty="userId" parameterType="com.chenzhou.mybatis.User">  
    insert into user(userName,password,comment)  
    values(#{userName},#{password},#{comment})  
 
 如上所示,我们在insert中指定了keyProperty="userId",其中userId代表插入的User对象的主键属性。
 
然后通过对象名打点的方式就可以获取到刚刚新增进去的id的值

转载于:https://www.cnblogs.com/fireinwater/p/6347591.html

你可能感兴趣的:(ssm框架获得实时的自增id)