下面的示例代码来自 BillingReportSpecification
使用 root.get
直接从模型Map变量并获取id的函数。
public class BillingReportSpecification {
public static Specification<BillingProcess> getReportFilter(BillingReportSearchRequest request) {
return new Specification<BillingProcess>() {
private static final long serialVersionUID = -1397887579564467889L;
@Override
public Predicate toPredicate(Root<BillingProcess> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
if (request.getBranchOfServiceId() != null) {
predicates.add(cb.equal(root.get("clientId").get("branchOfServiceId"), request.getBranchOfServiceId()));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
}
};
}
我想知道的是如何获得身份证 loanProduct
id)来自存储库的自定义查询(@query),而不是使用 root.get
功能。这是我在中进行的自定义查询 BillingProcessRepository.java
:
public interface BillingProcessRepository extends JpaRepository<BillingProcess, Long>, JpaSpecificationExecutor<BillingProcess>, MeteorAdapterRepository<BillingProcess, Long> {
public static final String FIND_LOAN_AND_LOAN_PRODUCT_TYPE = "SELECT client FROM Client client INNER JOIN Loan loan ON client.id = loan.client WHERE loan.loanProduct = :loanProduct";
@Query(FIND_LOAN_AND_LOAN_PRODUCT_TYPE)
BillingProcess findByLoanAndLoanProductType (@Param("loanProduct") Long loanProduct);
}
暂无答案!
目前还没有任何答案,快来回答吧!