JOOQ空状态

JOOQ empty condition

有没有办法定义在输出 sql 查询中什么都不产生的空条件?现在,对于默认条件,我使用 trueCondition()

private static Condition limitCondition(Integer offset, Integer count) {
    Condition limitCondition = trueCondition();
    if (count != null && offset != null) {
        limitCondition = rowNum.between(offset, count + offset);
    } else if (count == null && offset != null) {
        limitCondition = rowNum.greaterOrEqual(offset);
    } else if (count != null && offset == null) {
        limitCondition = rowNum.lessOrEqual(count);
    }
    return limitCondition;
}

DSL.noCondition() starting with jOOQ 3.11, which can act as an identity for both AND and OR operators, and doesn't produce any output unless strictly required (e.g. when projecting it in SELECT), in case of which it acts like DSL.trueCondition()

详情请见:

可能有点太晚了,但是在 3.14 版本中,有一个静态方法可以使用。

Condition result = trueCondition();

参考:jooq documentation