首页 > 其他 > 详细

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

时间:2015-10-14 14:29:42      阅读:106      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!