赞
踩
insert 插入标签并不难
只是为了注意一下,insert还有一些细节
如果你的数据库支持自动生成主键的字段(比如 MySQL 和 SQL Server),那么你插入时没有设置id的值,返回是如何获取插成功工完整的一行信息呢?
如果只判断成功,并把之前的值拿来使用,有缺少一个id的值,那么你还必须查询该值
<insert id="insertReturnId" parameterType="User">
<selectKey resultType="int" keyProperty="id" keyColumn="id" order="AFTER">
select LAST_INSERT_ID();
</selectKey>
insert into user(name) values (#{name})
</insert>
<insert id="insertReturnId" parameterType="User" useGeneratedKeys="true" keyProperty="id">
insert into user(name) values (#{name})
</insert>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。