idea将查询数据放入List时结果只重复显示最后一条数据(已解决)

部门源码(问题所在):
List<AqProjectType> list = new ArrayList<AqProjectType>();
AqProjectType aq = new AqProjectType();
while(rs.next()) {
aq.setId(rs.getString(1));
aq.setName(rs.getString(2));
aq.setCode(rs.getString(3));
aq.setREMARK(rs.getString(4));
aq.setSTATUS(rs.getString(5));
aq.setMakedep(rs.getString(6));
aq.setMakeuser(rs.getString(7));
aq.setInsert_date(rs.getString(8));
list.add(aq);
}

以上问题所在:
AqProjectType aq = new AqProjectType(); 

修改new对象的位置即可:

List<AqProjectType>  list = new ArrayList<AqProjectType>();
AqProjectType aq = null;       

while(xx.next()){
   aq = new AqProjectType();   
aq.setId(rs.getString(1));
aq.setName(rs.getString(2));
aq.setCode(rs.getString(3));
aq.setREMARK(rs.getString(4));
aq.setSTATUS(rs.getString(5));
aq.setMakedep(rs.getString(6));
aq.setMakeuser(rs.getString(7));
aq.setInsert_date(rs.getString(8));
list.add(aq);
}  

有被自己蠢到

posted @ 2021-12-21 15:22  fanguoan  阅读(220)  评论(0编辑  收藏  举报