[英]JOOQ dynamic set
我想只更新已更新的字段(它们不会为空)。 我想创建一个动态集,例如(不是有效的代码):
dslContext.update(table)
if(field1 != null) {
.set(field1, val1)
}
if(field2 != null) {
.set(field2, val2)
}
.where(condition1)
.and(condition2)
.execute();
有没有办法做到这一点?
虽然你可以通过(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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.