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類中的字段與數據庫中表的字段沒有對應