gpt4 book ai didi

mysql - Select Projections.constructor 中的子查询

转载 作者:可可西里 更新时间:2023-11-01 07:08:41 25 4
gpt4 key购买 nike

像这样尝试在带有投影的 Select 子句中编写子查询

queryFactory.query()
.select(
Projections.constructor(
MemberPaymentDTO.class,
JPAExpressions
.select(coopMember)
.from(coopMember)
.where(memberPayment.memberId.eq(coopMember))
.fetchOne(),
JPAExpressions
.select(paymentTransaction.amount)
.from(paymentTransaction)
.where(paymentTransaction.transactionId.eq(memberPayment.paymentTransaction.transactionId))
.fetchOne().floatValue(),
JPAExpressions
.select(collectionTransaction.price.multiply(collectionTransaction.quantity).sum())
.from(collectionTransaction)
.where(collectionTransaction.member.memberId.eq(memberPayment.memberId.memberId))
.where(collectionTransaction.paymentPeriod.paymentPeriodId.eq(paymentPeriodId))
.fetchOne().floatValue()

)
.from(memberPayment);

DTO如下

public class MemberPaymentDTO {
private CoopMember coopMember;
private float payableAmount;
private float collectionsAmount;


public MemberPaymentDTO(CoopMember coopMember, float payableAmount, float collectionsAmount) {
this.coopMember = coopMember;
this.payableAmount = payableAmount;
this.collectionsAmount = collectionsAmount;
}
}

上面代码的问题是Intellij Compiler complains Cannot resolve method 'constructor(java.lang.Class<re.iprocu.model.MemberPaymentDTO>, re.iprocu.model.CoopMember, float, float)

是否可以将子查询添加到 select 子句并在 DTO 中设置?怎么办?

最佳答案

我对 QueryDSL 不是很熟悉,但错误非常具体。

没有构造函数接受两个浮点值,在您的情况下,它们来自:

JPAExpressions
.select(paymentTransaction.amount)
.from(paymentTransaction)
.where(paymentTransaction.transactionId.eq(memberPayment.paymentTransaction.transactionId))
.fetchOne().floatValue()

和:

JPAExpressions
.select(paymentTransaction.amount)
.from(paymentTransaction)
.where(paymentTransaction.transactionId.eq(memberPayment.paymentTransaction.transactionId))
.fetchOne().floatValue()

API http://www.querydsl.com/static/querydsl/4.0.5/apidocs/com/querydsl/core/types/Projections.html指出 Projections.constructor 的可能用途是:

constructor(Class<? extends T> type, Expression<?>... exprs)
Create a constructor invocation projection for the given type and expressions

constructor(Class<? extends T> type, Class<?>[] paramTypes, com.google.common.collect.ImmutableList<Expression<?>> exprs)
Create a constructor invocation projection for given type, parameter types and expressions

constructor(Class<? extends T> type, Class<?>[] paramTypes, Expression<?>... exprs)
Create a constructor invocation projection for given type, parameter types and expressions

这意味着您没有正确调用电话。更仔细地阅读文档并搜索示例,基本上你在滥用 API。

关于mysql - Select Projections.constructor 中的子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45506865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com