英文:
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 = "UPDATE table_name SET field_two = :fieldTwo"
+ " WHERE field_one = :fieldOne AND field_two <> :fieldTwo";
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论