MyBatis中插入并返回主键

开发过程中经常遇到需要插入一条数据,并且返回这条数据自增的主键,在MyBatis中只需要在mapper中添加keyProperty属性即可

在mapper中添加keyProperty属性

 <insert id="insertAndGetId" parameterType="com.lili.log.dto.LogPay" useGeneratedKeys="true" keyProperty="payId" >
insert into t_log_pay (payId, orderId, waterNum,
studentId, coachId, payWay,
payMoney, couponMoney, couponId,
payTime)
values (#{payid,jdbcType=INTEGER}, #{orderid,jdbcType=VARCHAR}, #{waternum,jdbcType=VARCHAR},
#{studentid,jdbcType=BIGINT}, #{coachid,jdbcType=BIGINT}, #{payway,jdbcType=VARCHAR},
#{paymoney,jdbcType=DOUBLE}, #{couponmoney,jdbcType=DOUBLE}, #{couponid,jdbcType=INTEGER},
#{paytime,jdbcType=TIMESTAMP})
</insert>
上一篇:通过修改DNS达到不FQ也能访问Google(2018-12-25至现在已失效)


下一篇:Yum安装时出现 The program yum-complete-transaction is found in the yum-utils package