在Jdbi3中,如何使用bindBean()绑定相同字段?

huangapple go评论70阅读模式
英文:

In Jdbi3, how can I use bindBean() for same field?

问题

当Jdbi尝试第二次绑定field_two时,它会抛出UnableToCreateStatementException: Missing named parameter field_two in binding异常。

如何使用bindBean()绑定查询中多次出现的field_two

英文:

I have Java code:

String updateSql = "UPDATE table_name SET field_two = :field_two"
                + " WHERE field_one = :field_one AND field_two <> :field_two"; 
handle.createUpdate(updateSql)
    .bindBean(myBean)
    .execute();
@Data
public class MyBean() {
   private String fieldOne;
   private String fieldTwo;
}

When Jdbi tries to bind the field_two the second time, it throws UnableToCreateStatementException: Missing named parameter field_two in binding.

How can I bind the field_two appeared multiple times in the query using bindBean()?

答案1

得分: 0

绑定的名称需要与字段名称相同:

String updateSql = "UPDATE table_name SET field_two = :fieldTwo"
                + " WHERE field_one = :fieldOne AND field_two <> :fieldTwo";
英文:

It turns out that the binding needs to have the same name with the field name:

String updateSql = &quot;UPDATE table_name SET field_two = :fieldTwo&quot;
                + &quot; WHERE field_one = :fieldOne AND field_two &lt;&gt; :fieldTwo&quot;;

huangapple
  • 本文由 发表于 2023年2月14日 07:14:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442054.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定