条件分组
默认情况下,多个查询条件的关系为“与”,即需要多个条件同时满足。如果需要“或”的逻辑关系(某几个条件只需满足一个即可),只需将多个条件指定为相同的group
即可。
class Foo {
Long id;
int type1;
int type2;
}
class FooQo {
@QueryCondition(field="name")
String name;
@QueryCondition(group="group1")
int type1;
@QueryCondition(group="group1")
int type2;
}
FooQo fooQo = new FooQo("foo", 1, 2);
Specification<Foo> specification = SpecificationFactory.getSpecification(fooQo);
List<Foo> foos = fooRepository.findAll(specification);
生成的SQL:
SELECT * FROM FOO
WHERE LOWER(FOO.NAME) = 'foo'
AND (FOO.TYP1 = 1
OR FOO.TYPE2 = 2);
Last updated