Loading

MyBatis 插入时返回自增主键

XML

<insert id="insert" parameterType="com.stone.model.Person">
<!--
    selectKey 是做主键返回的
    keyProperty 接受返回主键的属性
    order: insert语句和生成主键的sql执行顺序;mysql是AFTER,在oracle中是BEFORE
    resultType:返回主键的数据类型
    生成主键的sql: select LAST_INSERT_ID()
-->
<selectKey keyProperty="personId" order="AFTER" resultType="java.lang.Integer">
    select LAST_INSERT_ID()
</selectKey
insert into person(name,gender,addr,birthday)
values(#{name},#{gender},#{addr},#{birthday})
</insert>

 

posted @ 2015-05-17 10:34  stono  阅读(332)  评论(0编辑  收藏  举报