jdbc查询返回来的List> 转换成List

public List find() {
    String sql = "select * from users";
    List<Users> users = new ArrayList<Users>();
    List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
    for (int i = 0; i < list.size(); i++) {//遍历设置实体
        Users user = new Users();
        user.setId((Integer) list.get(i).get("id"));
        user.setPassword(list.get(i).get("pwd").toString());
        user.setUserName(list.get(i).get("uname").toString());
        users.add(user);//添加到List<Users>
    }
    return list;
}

你可能感兴趣的:(jdbc查询返回来的List> 转换成List)