Use of Trim tags in dynamic SQL in MyBatis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.