我如何在以下jdbctemplate示例中指定’age’参数的值?
String sql = "SELECT * FROM CUSTOMER where age = ? ";
List<Customer> customers = new ArrayList<Customer>();
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
List<Map> rows = jdbcTemplate.queryForList(sql);
for (Map row : rows) {
Customer customer = new Customer();
customer.setCustId((Long)(row.get("CUST_ID")));
customer.setName((String)row.get("NAME"));
customer.setAge((Integer)row.get("AGE"));
customers.add(customer);
}
return customers;
解决方法:
您可以使用参数作为参数的queryForList()方法,例如:
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, theAge);
学习阅读API文档(以及一般文档).这就是你学习的方式.