1
select
    *
from person
WHERE (id like '%test%'
   or name like '%test%' 
    or location like '%test%'
 )
 and date >= '2019-10-24 00:00:00'
 and date < '2019-10-26 00:00:00' 

我怎么能用 Criteria 对象构造它?

MyExample example = new MyExample();
MyExample.Criteria criteria = example.createCriteria();
4

1 回答 1

1

对于较旧的生成器运行时,这种类型的查询并不容易。您需要以不同的方式考虑您的查询以使其正常工作。例如,对于布尔代数,您可以说...

(a | b | c) & d & e

在功能上等同于

(a & d & e) | (b & d & e) | (c & d & e)

使用旧的运行时可以使用第二种形式编写 where 条件,但这真的很难看。

我建议您改用较新的 MyBatis3DynamicSQL 运行时来生成代码。使用新的运行时,您可以完全按照您的意愿编写 where 子句。有关新运行时的更多信息,请参阅这些页面:

于 2019-10-24T13:30:58.230 回答