```java
private QMeasureIfMapPjt qMeasureIfMapPjt = new QMeasureIfMapPjt("measureIfMapPjt");
private QProjectSales qProjectSales = new QProjectSales("projectSales");
private QProjectPurchase qProjectPurchase = new QProjectPurchase("projectPurchase");
public MeasureRepositoryImpl() {
super(MeasureIfMapPjt.class);
}
@Override
public List<MeasureIfMapPjtDto> findAll(String companyCdB, String pjtYn) {
final JPAQueryFactory queryFactory = new JPAQueryFactory(this.getEntityManager());
BooleanBuilder builder = new BooleanBuilder();
//初始化组装条件(类似where 1=1)
Predicate predicate = qMeasureIfMapPjt.isNotNull().or(qMeasureIfMapPjt.isNull());
//执行动态条件拼装
predicate = companyCdB.isEmpty() ? predicate : ExpressionUtils.and(predicate, qMeasureIfMapPjt.companyCdB.eq(companyCdB));
predicate = pjtYn.equals("A") ? predicate : ExpressionUtils.and(predicate, qMeasureIfMapPjt.pjtCd.isEmpty()
.or(qMeasureIfMapPjt.pjtCd.isNull()));
return queryFactory.select(Projections.bean(MeasureIfMapPjtDto.class,
qMeasureIfMapPjt.companyCdB,
qMeasureIfMapPjt.idNo,
qMeasureIfMapPjt.seq.as("seq"),
qMeasureIfMapPjt.ifCustName,
qMeasureIfMapPjt.pjtCd,
qProjectSales.pjtName.as("pjtName"),
qMeasureIfMapPjt.dateFrom,
qMeasureIfMapPjt.dateTo
))
.from(qMeasureIfMapPjt).leftJoin(qProjectSales).on(qMeasureIfMapPjt.pjtCd.eq(qProjectSales.pjtCd))
.where(builder.and(predicate))
.fetch();
}
用的是jpa+querydls,
其中有3个表,projectsales ps,projectpurchase pp和measureifmappjt m
m表中有个字段是pjtcd,分别对应ps表和pp表中的pjtcd,
怎么实现关联查询,m表中的pjt对应到两个p表的pjtname,
元本打算用union来解决的,但是没有找到与之对应的方法,求大佬