简体   繁体   English

如何在jOOQ中结合条件

[英]How to combine Conditions in jOOQ

I have a list of conditions: 我有一份条件清单:

List<Condition> conditions = ...;

What is the easiest way to and-combine (or or-combine) these conditions into a new condition? 将这些条件组合(或组合)成新条件的最简单方法是什么?

Condition condition = and(conditions);

Does JOOQ have a utility function for this? JOOQ是否具有实用功能? I agree it is easy to write, but I would rather not re-invent the wheel. 我同意这很容易写,但我宁愿不重新发明轮子。

jOOQ 3.6+ solution. jOOQ 3.6+解决方案。

You can simply write: 你可以简单地写:

Condition condition = DSL.and(conditions);

Prior to jOOQ 3.6: 在jOOQ 3.6之前:

Before this was implemented in jOOQ 3.6 ( #3904 ) you had to resort to writing your own method: 在jOOQ 3.6( #3904 )中实现之前,你不得不求助于编写自己的方法:

static Condition and(Collection<? extends Condition> conditions) {
    Condition result = DSL.trueCondition();

    for (Condition condition : conditions)
        result = result.and(condition);

    return result;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM