码迷,mamicode.com
首页 > 其他好文 > 详细

两种方法获取MyBatis刚刚插入的id

时间:2017-06-09 15:23:59      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:mybatis   name   use   _id   type   generated   res   integer   对象   

主要就是在xml文件中的写法,其他省略

方法一:

<insert id="insert" parameterType="com.xxx.xxxx.pojo.User">
        insert into t_user (name) 
        values (#{user.name})
        <selectKey resultType="Integer" order="AFTER" keyProperty="user.userId">
            SELECT LAST_INSERT_ID() AS userId
        </selectKey>
</insert>

方法二:

<insert id="insert" parameterType="Spares"     
        useGeneratedKeys="true" keyProperty="id">    
        insert into system(name) values(#{name})    
</insert>

然后在调用的时候就可以用对象的get属性方法来获取了。

两种方法获取MyBatis刚刚插入的id

标签:mybatis   name   use   _id   type   generated   res   integer   对象   

原文地址:http://www.cnblogs.com/azhqiang/p/6971849.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!