gpt4 book ai didi

java - JOOQ selectQuery for Record5

转载 作者:行者123 更新时间:2023-11-30 10:57:47 25 4
gpt4 key购买 nike

我是 JOOQ 的新手。

我需要使用 SelectQuery 并返回结果,但它的返回类型是记录。是否可以将 selectQuery 与 Record5 一起使用?或者有其他解决方案吗?

    SelectQuery<Record> query = db.selectQuery();
query.addSelect(WARE.NAME, RECEIPTITEM.SALEPRICE, RECEIPTITEM.QUANTITY, RECEIPT.TSCCREATED, WARE.WARECATEGORYID);
query.addFrom(RECEIPT
.join(RECEIPTITEM).on(RECEIPT.ID.eq(RECEIPTITEM.RECEIPTID))
.join(OUTLET).on(OUTLET.ID.eq(RECEIPT.OUTLETID))
.join(WARE).on(WARE.ID.eq(RECEIPTITEM.WAREID)));
query.addConditions(RECEIPT.TSCCREATED.between(start, end)
.and(OUTLET.OWNERID.eq(ownerId)));
if (outletId != null) {
query.addConditions(RECEIPT.OUTLETID.eq(outletId));
}
if (merchantId != null) {
query.addConditions(RECEIPT.MERCHID.eq(merchantId));
}

最佳答案

您不能创建 SelectQuery<Record5<...>>用 jOOQ 打字。

这是因为 SelectQuery ( which is part of the model API ) 允许您通过 SelectQuery.addSelect() 继续向其中添加新列(你自己做过)。每个这样的调用都会使 Record5<...> 无效类型。

但是,如果动态部分只是附加条件,则不必使用模型 API 来构造动态 SQL。您可以像这样重写您的查询:

Condition condition = RECEIPT.TSCCREATED.between(start, end)
.and(OUTLET.OWNERID.eq(ownerId));

if (outletId != null) {
condition = condition.and(RECEIPT.OUTLETID.eq(outletId));
}
if (merchantId != null) {
condition = condition.and(RECEIPT.MERCHID.eq(merchantId));
}

Select<Record5<String, BigDecimal, Integer, Timestamp, Long>> select =
db.select(
WARE.NAME,
RECEIPTITEM.SALEPRICE,
RECEIPTITEM.QUANTITY,
RECEIPT.TSCCREATED,
WARE.WARECATEGORYID)
.from(RECEIPT
.join(RECEIPTITEM).on(RECEIPT.ID.eq(RECEIPTITEM.RECEIPTID))
.join(OUTLET).on(OUTLET.ID.eq(RECEIPT.OUTLETID))
.join(WARE).on(WARE.ID.eq(RECEIPTITEM.WAREID)))
.where(condition);

关于java - JOOQ selectQuery for Record5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32453234/

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