myBatis插入數據 並返回對象id

其實就是多個三個參數:
1.userGenerateKeys=true
2.指定使用對象的那個列作主鍵
3.指定使用數據庫的哪個列作主鍵 

<insert id="insertAndGetId" 
useGeneratedKeys="true"
 keyProperty="id" 
keyColumn="id" 
parameterType="com.entity.OrderRefundApply">
    insert into mall_order_refund_apply
    (order_no ,
     refund_apply_type)
    values (
      #{orderNo},
      #{refundApplyType}
    )
</insert>

服務調用:直接返回的就是Integer整型Integer  insertAndGetId(OrderRefundApply orderRefundApply);

 

mybatispuls的insert方法,默認就實現了,這個插件的話可以不用考慮

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章