Roles of the where Statement of mybatis

Source: Internet
Author: User

WhereThe statement is mainly used to simplify the where condition judgment in SQL statements. Let's take a look at an example and explain the advantages of where.

<Select id = "dynamicwheretest" parametertype = "blog" resulttype = "blog">
Select * From t_blog
<Where>
<If test = "title! = NULL ">
Title = # {Title}
</If>
<If test = "content! = NULL ">
And content = # {content}
</If>
<If test = "owner! = NULL ">
And owner =#{ owner}
</If>
</Where>
</SELECT>
The function of the where element is to output a where field where the where element is written. Another advantage is that you do not need to consider what the conditional output in the where element looks like, mybatis will help you intelligently. If all the conditions are not met, mybatis will find all records. If the output starts with and, mybatis will ignore the first and, of course, if it starts with or, mybatis will also ignore it. In addition, in the where element, you do not need to consider the space question. mybatis will help you intelligently add it. In the preceding example, if title = NULL and content! = NULL, the entire output statement will be select * From t_blog where content =#{ content}, instead of select * From t_blog where and content =#{ content }, because mybatis intelligently ignores the first and or. Java-Javascript

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.