MyBatis中插入並返回主鍵

開發過程當中常常遇到須要插入一條數據,而且返回這條數據自增的主鍵,在MyBatis中只須要在mapper中添加keyProperty屬性便可app

 

 在mapper中添加keyProperty屬性spa

 <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>
相關文章
相關標籤/搜索