MyBatis 新增获取自增主键的小坑

@Mapper中
Integer addHugong(@Param("hg") Hugong hg);

.xml中 如果传入是带了参数名,返回主键值时也需要带着才能返回去
<insert id="addHugong" parameterType="com.shiro.shirodemo.entity.Hugong"
useGeneratedKeys="true" keyProperty="hg.id" keyColumn="id">
insert into sys_hugong
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="hg.name != null">
name,
</if>
<if test="hg.sex != null">
sex,
</if>
<if test="hg.sfz != null">
sfz,
</if>
<if test="hg.phone != null">
phone,
</if>
<if test="hg.level != null">
level,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="hg.name != null">
#{hg.name,jdbcType=VARCHAR},
</if>
<if test="hg.sex != null">
#{hg.sex,jdbcType=VARCHAR},
</if>
<if test="hg.sfz != null">
#{hg.sfz,jdbcType=VARCHAR},
</if>
<if test="hg.phone != null">
#{hg.phone,jdbcType=VARCHAR},
</if>
<if test="hg.level != null">
#{hg.level,jdbcType=VARCHAR},
</if>
</trim>
</insert>
posted @ 2020-04-03 17:22  小帅Tianjs  阅读(289)  评论(0编辑  收藏  举报