在春季启动时通过JPA CrudRepository自定义查询执行

时间:2020-03-18 19:56:38

标签: java spring-boot jpa

我在执行JPA CrudRepository中的自定义查询时遇到了麻烦,在该查询中,查询的某些部分会因从其他资源接收到的数据量而异。 以下是我的数据库查询:

select * from documents where type='lmn' and ((patient_id = '1234' and hospital_id = 'xyz') OR (patient_id = '4567' and hospital_id = 'abc'))

现在这部分(患者ID ='1234'和hospital_id ='xyz')或(患者ID ='4567'和hospital_id ='abc')可以有所不同,因为我将通过循环创建

我尝试了以下解决方案,但没有一个起作用

@Query(value = ":query", nativeQuery = true) 
List<Documents> findDocumentsByQuery(@Param("query")String query);

@Query(value = "SELECT * FROM documents WHERE document_type=:documentType :subQuery", nativeQuery = true)
List<Documents> findDocumentsByDocumentTypeAndSubquery(@Param("documentType")String documentType,@Param("subQuery") String subQuery);

如果我无法通过CRUD存储库实现此目的。还有其他办法吗?

在这方面的任何帮助将不胜感激。谢谢

0 个答案:

没有答案
相关问题