【发布时间】:2020-05-20 23:31:48
【问题描述】:
我有这个 jOOQ 选择,根据参数值,where 条件应该等于或不等于一个值:
如果参数 = true:
Charts c = CHARTS.as("c");
context.select()
.from(c)
.where(c.CHART_TYPE.eq(100)) // note the eq
.orderBy(c.NAME)
.fetch();
如果参数 = 假:
Charts c = CHARTS.as("c");
context.select()
.from(c)
.where(c.CHART_TYPE.ne(100)) // note the ne
.orderBy(c.NAME)
.fetch();
我不想重复整个选择(在许多情况下比示例更复杂/更长)。有没有办法只根据参数设置where条件,然后插入到select中?
【问题讨论】: