mybatise框架sql语句中trim的使用

时间:2022-03-11 20:03:40

看到一块代码,第一次见到trim这种标签,于是开始研究了:

<insert id="userRegister" parameterType="UserModel">
insert into user
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId>10000">
userId,
</if>
<if test="wx!=null and !wx.equals(&quot;&quot;)">
weixin,
</if>
<if test="wb!=null and !wb.equals(&quot;&quot;)">
weibo,
</if>
<if test="userEmail!=null and !userEmail.equals(&quot;&quot;)">
userEmail,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId>10000">
#{userId},
</if>
<if test="wx!=null and !wx.equals(&quot;&quot;)">
#{wx},
</if>
<if test="wb!=null and !wb.equals(&quot;&quot;)">
#{wb},
</if>
<if test="userEmail!=null and !userEmail.equals(&quot;&quot;)">
#{userEmail},
</if>
</trim>
</insert>

然后,百度出一些资料:

    1. trim 属性

        prefix:前缀覆盖并增加其内容

        suffix:后缀覆盖并增加其内容

        prefixOverrides:前缀判断的条件

        suffixOverrides:后缀判断的条件