為什么我返回的是“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());
??}
運(yùn)行結(jié)果為
com.imooc.model.Goddess@41cf53f9
2016-06-28
需要復(fù)習(xí)Goddess的toString()方法。默認(rèn)是Object類的toString()實(shí)現(xiàn)。
//Object類中實(shí)現(xiàn)如下:
public String toString() {
return getClass().getName() + "@" + Integer.toHexString(hashCode());
? ? }