为什么我返回的是“com.imooc.model.Goddess@41cf53f9”
GoddessDao 部分的代码
public List<Goddess> query1(List<Map<String, Object>> parmas) throws Exception{
List<Goddess> gs = new ArrayList<Goddess>();
StringBuilder sb = new StringBuilder();
sb.append("select" +
" user_name,sex,age,birthday,email,mobile" +
" from goddess where 1=1");
if (parmas != null && parmas.size() > 0) {
for (int i = 0; i < parmas.size(); i++) {
Map<String, Object> map = parmas.get(i);
sb.append(" and "+map.get("name")+" "+map.get("rela")+" "+map.get("value"));
}
}
PreparedStatement ptmt = conn.prepareStatement(sb.toString());
System.out.println(sb.toString());
ResultSet rs = ptmt.executeQuery();
Goddess g = null;
while (rs.next()) {
g = new Goddess();
g.setUser_name(rs.getString("user_name"));
g.setSex(rs.getInt("sex"));
g.setAge(rs.getInt("age"));
g.setBirthday(rs.getDate("birthday"));
g.setEmail(rs.getString("email"));
g.setMobile(rs.getString("mobile"));
gs.add(g);
}
return gs;
}
GoddessAction 部分的代码
GoddessDao gd = new GoddessDao();
List<Map<String, Object>> parmas = new ArrayList<Map<String,Object>>();
Map<String, Object> parma = new HashMap<String, Object>();
parma.put("name", "user_name");
parma.put("rela", "=");
parma.put("value", "'kerry");
parmas.add(parma);
List<Goddess> g = gd.query1(parmas);
for (int i = 0; i < g.size(); i++) {
System.out.println(g.get(i).toString());
}
运行结果为
com.imooc.model.Goddess@41cf53f9