The trim tag is somewhat similar to the replace effect.
Trim Property
Prefix: Prefixes overwrite and increase their contents
Suffix: suffixes overwrite and increase their contents
Prefixoverrides: Criteria for judging prefixes
Suffixoverrides: The condition of the suffix judgment
<!--Modified-
<update id= "Updatetest" >
UPDATE Test
<trim prefix= "SET" suffixoverrides= "," >
<if test= "Name!=null and name!=" >
name = #{name},
</if>
<if test= "Phone!=null and phone!=" >
Phone = #{phone},
</if>
<if test= "Address!=null and address!=" >
Address = #{address},
</if>
</trim>
WHERE
id = #{id}
</update>
Output SQL
Update Test Set name = #{name}, phone = #{phone}, address = #{address} WHERE
id = #{id}
<select id= "Checkuserbyphone" parametertype= "User" resultmap= "UserMap" >
SELECT * FROM user
<trim prefix= "WHERE" prefixoverrides= "and | OR ">
<if test= "Userid!=null and userid!=" >
and user_id! = #{userid}
</if>
<if test= "Phone!=null and phone!=" and state!= ' all ' >
and phone = #{phone} and state!= ' X '
</if>
</trim>
</select>
Output SQL SELECT * from user WHERE user_id! = #{userid} and phone = #{phone} and state!= ' X '
My batis mapper.xml in dynamic SQL using the Trim label if End scenario