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方法,默认就实现了,这个插件的话可以不用考虑

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