Trim is a formatted tag that can perform the functions of a set or a where tag. Trim Properties:
prefix: Prefixes overwrite and increase their contents
suffix: Suffix overrides and increases its contents
Prefixoverrides: The condition of the prefix judgment
Suffixoverrides: Suffix judgment Condition 1, select * from user <trim prefix= "WHERE" prefixoverride= "and |or" > <if test= "Name! = null and Name.length () >0 "> and name=#{name}</if> <if test=" Gender! = null and Gender.length () >0 "> and Gend Er=#{gender}</if> </trim> If the value of name and gender is not NULL, the print SQL is: SELECT * from user where name = ' xx ' and gender = ' xx ' in the place where the red mark is not present the first and, the above two attributes mean the following:
prefix: Prefix
Prefixoverride: Remove the first and or 2.update user <trim prefix= "set" suffixoverride= "," suffix= "Where id = #{id}" > <if test= "n Ame! = null and Name.length () >0 "> Name=#{name}, </if> <if test=" Gender! = null and Gender.length () > 0 "> Gender=#{gender}, </if> </trim> if the value of name and gender is not NULL, the printed SQL is: Update user set name= ' xx ', Gende R= ' xx ' where id= ' x ' does not have a comma in the red flag, and automatically adds a set prefix and a where suffix, the above three attributes have the following meanings, with the prefix meaning as above:
Suffixoverride: Remove the last comma (or another tag, as in the previous prefix)
suffix: suffix
Use of Trim tags in dynamic SQL in MyBatis