Mybatis中的update动态SQL语句 <trim></trim> 用法

 

Mybatis Mapper中文件中

update时,需要set设置多个字段,有时逗号处理时,会报错误,所以会使用到<trim></trim>

使用trim就是为了删掉最后字段的“,”。
主要不用单独写SET了,因为set被包含在trim中了:

<update id="update" parameterType="com.entity.Entity">
        <trim prefix="set" suffixOverrides=",">
            <if test="isPublish!=null">
                is_publish = #{isPublish},
            </if>
        </trim>
        WHERE id = #{id}
</update>     

 

posted on 2017-09-25 20:38  Xiaox-xin  阅读(1716)  评论(0编辑  收藏  举报

导航