mybatis useGeneratedKey与keyProperty

<insert id="insert" parameterType="com.mall.pojo.OrderItem" useGeneratedKeys="true" keyProperty="id">
insert into mmall_order_item (id, user_id, order_no,
product_name, product_id, product_image,
current_unit_prices, quality, table_price,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{orderNo,jdbcType=BIGINT},
#{productName,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{productImage,jdbcType=VARCHAR},
#{currentUnitPrices,jdbcType=DECIMAL}, #{quality,jdbcType=INTEGER}, #{tablePrice,jdbcType=DECIMAL},
now(), now())
</insert>
将userGeneratedKey值至为true,keyProperty="主键",即可获得插入后的主键id
.
原文地址:https://www.cnblogs.com/Dar-/p/9077350.html