今天使用以下方法从数据库中查询数据, 返回列表
- 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 类中的字段与数据库中表的字段没有对应
来源: http://www.bubuko.com/infodetail-3033733.html