在练习 jsp 项目是突然发现 订单页内容重复展示
在数据库按照用户名字段查询 是应该有三条不同订单的
在后台查询测试 发现问题同样如此
public static void main(String[] args) {
DingDanDao ddd = new DingDanDaoImpl();
List<DingDan> danList = ddd.selectById("admin");
for (DingDan dingDan : danList) {
System.out.println(dingDan.getEp_name()+"\t"+dingDan.getEo_create_time());
}
经过不断排查 测试,终于发现问题
实体类声明放在了循环外面, 将其放在循环内部 问题解决
public List<DingDan> selectById(String id) {
List<DingDan> danList = new ArrayList<>();
String sql = "select * from EASYBUY_ORDER eo,EASYBUY_ORDER_DETAIL eod,EASYBUY_PRODUCT ep where eo.eo_user_id=? and eod.eo_id=eo.eo_id and eod.ep_id= ep.ep_id order by eo.eo_id desc";
Object[] params = {id};
ResultSet rs = this.executeQuery(sql, params);
try {
while (rs.next()){
DingDan d = new DingDan();
d.setEo_id(rs.getInt("Eo_id"));
d.setEo_user_id(rs.getString("Eo_user_id"));
d.setEp_name(rs.getString("Ep_name"));
d.setEp_file_name(rs.getString("Ep_file_name"));
d.setEp_price(rs.getInt("Ep_price"));
d.setEod_quantity(rs.getInt("Eod_quantity"));
d.setEp_stock(rs.getInt("Ep_stock"));
d.setEo_create_time(rs.getString("eo_create_time"));
danList.add(d);
}
} catch (SQLException throwables) {
throwables.printStackTrace();
}finally {
closeResource();
}
return danList;
}
后端测试
前端展示