【问题标题】:JOOQ dynamic setJOOQ动态集
【发布时间】:2017-08-12 21:04:11
【问题描述】:

我只想更新已更新的字段(它们不会为空)。 我想创建一个动态集,例如(不是有效代码):

dslContext.update(table)
            if(field1 != null) {
              .set(field1, val1)
            }
            if(field2 != null) {
              .set(field2, val2)
            }
            .where(condition1)
            .and(condition2)
            .execute();

有没有办法做到这一点?

【问题讨论】:

    标签: java sql jooq


    【解决方案1】:

    虽然您当然可以通过 (ab) 使用 DSL API 来实现这一点,但实际做到这一点的最佳方法是使用以下方法之一:

    一个使用Record的例子:

    Record record = dslContext.newRecord(table);
    
    if (field1 != null)
        record.set(field1, val1)
    
    if (field2 != null) {
        record.set(field2, val2)
    
    dslContext.update(table)
              .set(record)
              .where(condition1)
              .and(condition2)
              .execute();
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 1970-01-01
      • 2020-10-05
      • 2012-12-12
      • 2020-10-07
      • 2021-09-26
      • 2018-04-09
      • 2018-10-05
      • 2021-08-23
      相关资源
      最近更新 更多