Mybatis实现插入数据的时候将主键赋值给对象的两种方法

<insert id="insertCustomer2" parameterType="Customer">

/* order="AFTER"表示在下面的插入语句执行之后在执行 */
<selectKey keyColumn="cust_id" order="AFTER" keyProperty="custId" resultType="Integer">
select last_insert_id()
</selectKey>

insert into `customer` (cust_name,cust_profession,cust_phone,email) values
(#{custName},#{custProfession},#{cusPhone},#{custEmail})
</insert>

<insert id="insertCustomer3" parameterType="Customer"
useGeneratedKeys="true" keyProperty="custId" keyColumn="cust_id">
insert into `customer` (cust_name,cust_profession,cust_phone,email)
values (#{custName},#{custProfession},#{custPhone},#{custEmail})
</insert>


原文链接:https://blog.csdn.net/shijiujiu33/java/article/details/88541110

posted @ 2020-05-23 18:47  易不易  阅读(1169)  评论(0编辑  收藏  举报