public List<Message> getAllMessage(String sql,String[] args) throws Exception {
// TODO Auto-generated method stub
ResultSet rs = this.executeQuery(sql, args);
List<Message> list = new ArrayList<Message>();
// Message message = new Message(); //2处
try {
while(rs.next())
{
Message message = new Message(); //1处
message.setId(rs.getInt("id"));
message.setName(rs.getString("name"));
message.setPhone(rs.getString("phone"));
message.setEmail(rs.getString("email"));
message.setTitle(rs.getString("title"));
message.setContent(rs.getString("content"));
System.out.println(message.getId()+"-------------");
list.add(message);
}
for (Message a : list) {
System.out.println(a.getId()+"aaaaaaaaaaaaaaaaaaa");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
throw new Exception(" com.webbook.impl.MessageDaoImpl.public List<Message> getAllMessage(String sql,String[] args)方法异常",e);
}
return list;
}
如果把1处注释掉,2处放开,结果会反复出现最后一条数据。