spring--jdbcTemplate查询返回对象集合

 public class News {
    private String id;
    private String title;
    private String content;
    private String time;
    private String htmlPath;
    
set/get...
 }


  public List<News> queryNewsByContent(String content) {
        
        String sql = "select id,title,content from news where  content like '%" + content + "%'";


        List<News> list = jdbcTemplate.query(sql, new RowMapper<News>() {
            @Override
            public News mapRow(ResultSet rs, int rowNum) throws SQLException {
                News news = new News();
                news.setId(rs.getString("id"));
                news.setTitle(rs.getString("title"));
                news.setContent(rs.getString("content"));
                return news;
            }
        });
        return list;
    }