请提供任何帮助。我有一个称为私有无效更新数据库的方法,其内部代码如下。我想知道有什么方法可以缩短代码而无需重复吗?
firstNameColumn.setOnEditCommit(event -> {
Customer customer = event.getRowValue();
customer.setfirstName(event.getNewValue());
try {
Utils.getInstance().update("firstName",event.getNewValue(),customer.getId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
middleNameColumn.setOnEditCommit(event -> {
Customer customer = event.getRowValue();
customer.setfirstName(event.getNewValue());
try {
Utils.getInstance().update("middleName",customer.getId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
lastNameColumn.setOnEditCommit(event -> {
Customer customer = event.getRowValue();
customer.setfirstName(event.getNewValue());
try {
Utils.getInstance().update("lastName",customer.getId());
} catch (SQLException e) {
throw new RuntimeException(e);
}
});
我具有以下字段:名列,中间名列和姓氏列,但是它们在方法内重复。