My batis mapper.xml in dynamic SQL using the Trim label if End scenario

Source: Internet
Author: User
Tags sql using

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

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.