Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the trim tag of mybatis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Mybatis trim tag how to use, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.

The following are the attributes involved in the trim tag:

Here are a few examples to illustrate the use of trim tags.

1. Use trim tags to remove redundant and keywords

There is an example of this:

SELECT * FROM BLOG

WHERE

State = # {state}

If >

AND title like # {title}

If >

AND author_name like # {author.name}

If >

Select >

What happens if none of these conditions match? Eventually the SQL will look like this:

SELECT * FROM BLOG

WHERE

This causes the query to fail. What if only the second condition matches? The SQL will end up like this:

SELECT * FROM BLOG

WHERE

AND title like 'someTitle'

You can use the where tag to solve this problem, and the where element inserts the "WHERE" clause only if the condition of at least one child element returns the SQL clause. Also, if the statement begins with "AND" or "OR", the where element removes them.

SELECT * FROM BLOG

State = # {state}

If >

AND title like # {title}

If >

AND author_name like # {author.name}

If >

Where >

Select >

Trim tags can also perform the same function, written as follows:

State = # {state}

If >

AND title like # {title}

If >

AND author_name like # {author.name}

If >

Trim >

2. Use trim tags to remove extra commas

There are the following examples:

If the conditions in the red box do not match, the sql statement will look like this:

INSERT INTO role (role_name,) VALUES (roleName,)

The insert will fail. Using the trim tag can solve this problem with only a few modifications, as shown below:

One of the most important attributes is

SuffixOverrides= ","

Means to remove the extra comma at the end of the sql statement

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report