需在<insert…/>标签中加 useGeneratedKeys=“true” keyProperty=“id” ,返回的主键id存储在作为参数的实体类中。
<insert id="insertAllMart" useGeneratedKeys="true" keyProperty="id" parameterType="com.mbyte.easy.admin.entity.MaterialMart" >
insert into t_material_mart (user_id, title, Icon, content,introduction, price, phone_number, create_time, update_time)
values (
#{materialMart.userId,jdbcType=BIGINT},
#{materialMart.title,jdbcType=VARCHAR},
#{materialMart.Icon,jdbcType=VARCHAR},
#{materialMart.content,jdbcType=VARCHAR},
#{materialMart.introduction,jdbcType=DECIMAL},
#{materialMart.price,jdbcType=DECIMAL},
#{materialMart.phoneNumber,jdbcType=INTEGER},
#{materialMart.createTime,jdbcType=TIMESTAMP},
#{materialMart.updateTime,jdbcType=TIMESTAMP}
)
</insert>