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>

猜你喜欢

转载自www.cnblogs.com/Tian-J-Shuai/p/12627703.html
今日推荐