如何建立标准以使用左连接和条件而不是 where

问题描述 投票:0回答:0

我正在使用 criteria api 来构建这样的查询

我测试过:

List<Predicate> predicates = new ArrayList<>();
Join<Brand, Model> modelJoin = root.join(Brand_.models, JoinType.LEFT);
Predicate p = criteriaBuilder.equal(modelJoin.get(Model_.type), "SUV"));
predicates.add(p);  // Need to add predicate to this list  

我也测试过

List<Predicate> predicates = new ArrayList<>();
Join<Brand, Model> modelJoin = root.join(Brand_.models, JoinType.LEFT);
modelJoin.on(criteriaBuilder.equal(modelJoin.get(Model_.type), "SUV"));

但在这里我不知道如何将其添加到谓词列表

我期待有这样的东西:

SELECT * from brand b left join model m on b.id=m.brand_id and b.type='SUV'

但我得到的是:

SELECT * from brand b left join model m on b.id=m.brand_id where b.type='SUV'
spring-boot jpa spring-data-jpa spring-data criteria-api
© www.soinside.com 2019 - 2024. All rights reserved.