spring jdbcTemplate query 返回值为null
今天使用以下方法从数据库中查询数据,返回列表
public List<BookBean> getBooks(){
String sql = "select * from books where inventory > 0 order by title";
List<BookBean> books = jdbcTemplate.query(sql, new BeanPropertyRowMapper<BookBean>(BookBean.class));
return books;
}
但是打印出结果时发现都是null,查找了下原因,主要有以下几点
- bean类中没有setter方法
- bean类中的字段与数据库中表的字段没有对应