空值处理
默认情况下,查询条件构建过程会直接忽略查询对象中的null
字段。如果使用者希望将null
也加入到条件中,需配置@QueryCondition(policy=NullPolicy.INCLUDE)
。
对于字符串类型的查询条件,默认会进行去除首尾空白字符的处理,如果不希望使用这一特性,使用者需要配置@QueryCondition(trim=false)
。
class Foo {
Long id;
String name;
String content;
}
class FooQo {
@QueryCondition
String name;
@QueryCondition(policy=NullPolicy.INCLUDE)
String content;
}
FooQo fooQo = new FooQo("foo ", null);
Specification<Foo> specification = SpecificationFactory.getSpecification(fooQo);
List<Foo> foos = fooRepository.findAll(specification);
生成的SQL:
SELECT * FROM FOO
WHERE FOO.NAME = 'foo'
AND FOO.CONTENT IS NULL;
Last updated