Java – mybatis “or” standard
•
Java
I want to create a query with mybatis, which will produce the following:
SELECT first_field,second_filed,third_field WHERE first_field > 1 AND (second_field > 0 OR third_field < 0)
How can I construct it with a criteria object?
Solution
One method is to extend the generated example classes:
Basically, generate sample classes and add custom conditions
public Criteria multiColumnOrClause(String value1,String value2) { addCriterion("value1 = " + value1 + " OR value2 = " + value2); return this; }
If you often reuse it and don't want to do this for all mappers, you can also extract logic in the plug-in. Although the document is a little lacking, there is only one example:
org. mybatis. generator. plugins. CaseInsensitiveLikePlugin
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码