在采用逻辑删除的系统中,查询条件需要拼接固定的IS_DELETED = 0语句。类似的场景下,开发者可以定义一个基本的查询条件对象,其他查询条件继承并扩展条件即可。
IS_DELETED = 0
class Foo { Long id; String name; Boolean isDeleted; } class BaseQo { @QueryCondition boolean isDeleted = false; } class FooQo extends BaseQo { @QueryCondition String name; } FooQo fooQo = new FooQo("foo"); Specification<Foo> specification = SpecificationFactory.getSpecification(fooQo); List<Foo> foos = fooRepository.findAll(specification);
生成的SQL:
SELECT * FROM FOO WHERE LOWER(FOO.NAME) = 'foo' AND FOO.IS_DELETED = 0;
ORM框架会自动将布尔值false/true分别转换为0/1。
false
true
0
1
Last updated 6 years ago