spring jdbcTemplate query 返回值为null

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,查找了下原因,主要有以下几点

  1. bean类中没有setter方法
  2. bean类中的字段与数据库中表的字段没有对应

猜你喜欢

转载自www.cnblogs.com/d-i-p/p/10757734.html