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

上一篇:第11课 使用子查询


下一篇:《mysql必知必会》基础实践