SQL statements in MyBatis can be dynamically generated and spelled with conditional judgments
1. Use if+where to spell SQL statements
, use if to determine the spelling of SQL according to the parameters passed in
2. Using Trim+if to implement the spelling of SQL
There are some properties in Trim:
"1" prefix: prefix
"2" prefixoverrides= "and | Or "Override the prefix to avoid occurrences of the and OR or
"3" suffix= "" suffix, and at the end of Trim plus
"4" suffixoverrides= "" suffix rewrite, in each if in the SQL statement after adding, to avoid unnecessary
3. Update with If+set (set will automatically ignore end,)
4. When a range operation is required, a foreach is usually used
Such as:
Use the Foreach loop to facilitate the variable passed into the parameter list. Properties of foreach:
Collection= "": If the passed parameter is a number, write the Array, if the passed parameter is list, then write the list, if the incoming parameter is map, write the corresponding key name in the map
Item: Refers to the current object
Open: Start
Close: End
Separator: Delimiter
5. Use Choose (when,otherwise) similar to switch in Java
Otherwise refers to other conditions
MyBatis Dynamic SQL