您的位置:首页 > 数据库 > MySQL

MyBatis+MySQL 返回插入的主键ID

2017-03-23 14:56 387 查看

MyBatis+MySQL 返回插入的主键ID

<insert id="insertSelective"  useGeneratedKeys="true" keyProperty="id"  parameterType="com.model.Channel" >
insert into channel
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="shopId != null" >
shop_id,
</if>
......


学习:
http://www.cnblogs.com/gengaixue/p/5276596.html
或者:

<insert id="insertSelective" parameterType="com.tuling.model.Channel" >
<selectKey keyProperty="id" resultType="int">
select LAST_INSERT_ID()
</selectKey>
insert into channel
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="shopId != null" >
shop_id,
</if>
......
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: