【发布时间】:2021-09-22 00:28:42
【问题描述】:
在我正在开发的 Spring Boot api 中,查询过滤器已准备好从客户端进入,以便进入 where 子句
要通过存储库进行的 jpa(或者更确切地说是 sql)查询。
例如。假设有一个 Book 实体,其字段为 title、author、edition。
所有Book-s 都将使用过滤器String like 进行查询
String str = "title = 'cooking' or 'recipes' and edition > 5";
这个子句可以直接输入到where子句中,如下:
select *
from book
where title = 'cooking' or 'recipes' and edition > 5 ;
问题是,如何直接从这个查询过滤字符串创建org.springframework.data.jpa.domain.Specification?是否可以从 str 创建一个 Specification 实例,而无需以任何方式解析/处理它?
我将对结果进行分页。因此,对 jpa 的EntityManager 的显式调用是行不通的。它必须在存储库中。
TIA。
【问题讨论】:
标签: java sql spring-boot filter spring-data-jpa