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