Mybatis插入后返回主键

<insert id="add" parameterType="vo.Category">

<selectKey resultType="java.lang.Short" order="AFTER" keyProperty="id">

SELECT LAST_INSERT_ID()

</selectKey>

insert into category (name_zh, parent_id,

show_order, delete_status, description

)

values (#{nameZh,jdbcType=VARCHAR},

#{parentId,jdbcType=SMALLINT},

#{showOrder,jdbcType=SMALLINT},

#{deleteStatus,jdbcType=BIT},

#{description,jdbcType=VARCHAR}

)

</insert>


在插入操作完成之后,参数category的id属性就已经被赋值了

执行完mapper.insert(category);获取插入返回的主键用category.getId()就可以了

posted @ 2012-03-21 15:37  刘振明  阅读(15509)  评论(0编辑  收藏  举报