------解决方案-------------------- public List<CustomerDevote> getList() { List<Customer> list1 = baseDao.getList(obj); List<CustomerDevote> list2 = new ArrayList<CustomerDevote>(); int sum = 0;
for(Customer c : list1) { CustomerDevote cd = new CustomerDevote();//为什么不放在里面,你那个应该是只添加了一个元素,但是也应该不会出现转型问题。。有没调错函数 sum = 0; for(Order o : c.getOrders()) { sum += o.getTotalPrice(); } cd.setCustomerId(c.getId()); cd.setCustomerName(c.getName()); cd.setOrderCount(c.getOrders().size()); cd.setTotalMoney(sum); list2.add(cd); } return list2; }