1. 程式人生 > >mybatis配置檔案mapper.xml中trim標籤的用法

mybatis配置檔案mapper.xml中trim標籤的用法

在mapper.xml中對statement的定義,可以用<trim>來填充和隱藏sql語句。

<!--修改user的statement-->
<update id="updateUser" parameterType="user">
update user 
<trim prefix="set" suffixOverrides=",">
<if test="userPassword!=null">
user_password=#{userPassword},
</if>
<if test="userType!=null">
user_type=#{userType},
</if>
</trim>
where user_id=#{iD}
</update>

標籤:trim

屬性:

1.prefix--》在trim標籤定義的內容前填充對應內容

2.prefixOverrides--》在trim定義的中,隱藏頭部對應的內容

3. suffix--》在trim標籤定義的內容後填充內容

4.suffixOverrides--》在trim定義的中,隱藏尾部對應的內容