public List<Person> findInfo(Integer id) {
List<Person> list = new ArrayList<Person>();
String sql = "";
try{
if(id==null){
sql = "select id,name,psw from student";
}else{
sql = "select id,name,psw from student where id="+id;
}
// String sql = "select name,psw from student";
List<Map<String,Object>> rows = jdbcTemplate.queryForList(sql);
for(Map<String,Object> row : rows){
Person p = new Person();
System.out.println(row.get("name")=="");
System.out.println((row.get("name"))==null);
System.out.println(row.get("name").equals(""));
System.out.println("".equals(row.get("name")));
if((row.get("name")!="") && (row.get("psw")!= "")){
p.setName((String) row.get("name"));
p.setPassword((String) row.get("psw"));
p.setId((Integer) row.get("id"));
list.add(p);
}
}
}catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
return list;
}
以上是报错代码,我将id设置为Integer,数据库里也是Integer,但是查完后传值过程中说数据库的查出来的是long型,无法转为Integer,解决办法
p.setId((Integer) row.get("id"));换为p.setId(new Integer(String.valueOf(row.get("id"))));
ok解决