我有一个这样的存储库
@Repository
public interface LeadRequestRepository extends PagingAndSortingRepository<LeadRequest, UUID> {
@Query(value = "SELECT * FROM lead_request WHERE product IN :products AND current_status in :status", nativeQuery = true)
List<LeadRequest> findLeadRequests(@Param("products") List<String> products, @Param("status") List<String> status);
}在此查询中,状态可以为null或空列表。
在这种情况下,查询必须返回所有状态(新建、已批准、已拒绝等)。换句话说,查询必须变成SELECT * FROM lead_request WHERE product IN :products,而不是status子句。
我也很困惑,因为我使用了IN子句,所以我不能使用JPA示例API
我如何使用hibernate和jpa来实现这一点?
发布于 2020-03-06 19:57:10
有两个选项:
Specifications的JPA标准查询提供了抽象。看一看Spring Data JPA docs herehttps://stackoverflow.com/questions/60562756
复制相似问题