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

MyBatis插入时候获取自增主键方法

时间:2015-10-14 14:31:29      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

MyBatis 3.2.6插入时候获取自增主键方法有二

以MySQL5.5为例:

方法1:

<insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
        insert into person(name,pswd) values(#{name},#{pswd})
</insert>

注:需要Person.getId()

方法二:

<insert id="insert" parameterType="Person">
        <selectKey keyProperty="id" resultType="long">
            select LAST_INSERT_ID()
        </selectKey>
        insert into person(name,pswd) values(#{name},#{pswd})
</insert>


MyBatis插入时候获取自增主键方法

标签:

原文地址:http://my.oschina.net/ydsakyclguozi/blog/517078

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