看到一块代码,第一次见到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("")">
weixin,
</if>
<if test="wb!=null and !wb.equals("")">
weibo,
</if>
<if test="userEmail!=null and !userEmail.equals("")">
userEmail,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId>10000">
#{userId},
</if>
<if test="wx!=null and !wx.equals("")">
#{wx},
</if>
<if test="wb!=null and !wb.equals("")">
#{wb},
</if>
<if test="userEmail!=null and !userEmail.equals("")">
#{userEmail},
</if>
</trim>
</insert>
然后,百度出一些资料:
-
-
trim 属性
prefix:前缀覆盖并增加其内容
suffix:后缀覆盖并增加其内容
prefixOverrides:前缀判断的条件
suffixOverrides:后缀判断的条件
-