java—如何使用规范而不使用root.get,而是使用存储库中的自定义查询

laawzig2  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(200)

下面的示例代码来自 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);

}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题