mybatis 动态新增
<insert id="insertSelective" parameterType="com.yimayhd.snscenter.client.domain.ComentDO" useGeneratedKeys="true" keyProperty="id" >
insert into com_coment<trim prefix="(" suffix=")" suffixOverrides="," >
domain,
status,
<if test="gmtCreated != null" >
gmt_created,
</if>
<if test="gmtModified != null" >
gmt_modified,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
#{domain,jdbcType=INTEGER},
#{status,jdbcType=INTEGER},
<if test="gmtCreated != null" >
#{gmtCreated,jdbcType=TIMESTAMP},
</if>
<if test="gmtModified != null" >
#{gmtModified,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
本文详细介绍了MyBatis中使用动态SQL进行新增操作的方法,包括如何使用`<trim>`标签来处理参数的可选性,以及如何利用`useGeneratedKeys`和`keyProperty`属性来获取自增ID。
6333

被折叠的 条评论
为什么被折叠?



