如何在 Jooq 中使用带有 update 语句的 ArrayList 字段

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

我的 jooq 版本 3.14.6 有问题。我想使用更新语句进行字段搜索 - pr_id 和 m_id 如下所示:

public Result<?> save(Long id, Request req) {
   Condition condition = field("send.pr_id").eq(id)
                .and(field("send.m_id").eq(req.getMemId));

   condition = req.applyConditions(condition);

   return ctx.update(table(snp).as("send"))
              .set(field("status"), "D")
              .where(condition)
              .returning()
              .fetch();
} 

也在类请求中我有这个代码:

public class Request {
   Integer prId;

   List<Long> memId;

   public Condition applyConditions(Condition condition) {
       Condition mod = condition;

       if(Objects.nonNull(prId)) {
          mod = mod.and(field("send.pr_id")).eq(prId);
       }

       if(Objects.nonNull(memId)) {
          mod = mod.and(field("send.m_id")).eq(memId);
       }
       return modified;
   }
} 

在我的表格中,我有列 -

pr_id bigint not null, status char(1) not null, m_id bigint not null etc..

当我启动我的项目并在邮递员中使用休息请求(http://localhost:8080/api/v1/pr/17)时,如下所示:

{“memId”:[ 2, 4, 6 ] }

我收到错误:

“方言 postgres 不支持类型类 java.util.ArrayList”

此错误与不正确的字段 memId 相关

如何更正此代码?

java spring postgresql spring-boot jooq
1个回答
1
投票

您无法使用

=
将列与 SQL 中的列表进行比较。只需使用
IN
谓词
即可:

field("send.m_id").in(memId)

请注意:我强烈建议您使用 jOOQ 进行代码生成,除非您的模式是动态的。但考虑到您正在为表/列名称传递常量字符串文字,它可能不是。

© www.soinside.com 2019 - 2024. All rights reserved.