Java模糊方法调用

时间:2016-12-04 22:46:33

标签: java spring lombok

代码在这里:

@RequestMapping(value = "/orderDetail", method = RequestMethod.GET)
    public String orderDetail(Model model, @ModelAttribute("order") Order order, @RequestParam(value="orderId", required=false, defaultValue = "-1") int orderId) {
        Store store = storeRepo.findByName(EMarketApp.STORE_NAME).get(0);
        if (orderId >= 0 &&
                (!(store.getOrderList().isEmpty()))) {
            // modify
            Order o2 = store.getOrderList().stream().filter(o -> (((Order) o).getId() == orderId)).findAny().get();
            order.setId(o2.getId());
            order.setItems(o2.getItems());
            order.setDateOrdered(o2.getDateOrdered());

            //get the cost of the products ...

            Double cost =0.0;
            for(Item item: order.getItems()){
                cost+=item.getPrice() * item.getAmount();
            }
            model.addAttribute("orderCost", cost);

        }
        return "form/orderDetail";
    }

它表示模糊的方法调用:

order.setId(o2.getId());
order.setItems(o2.getItems());
order.setDateOrdered(o2.getDateOrdered());

但是我不明白,顺序和o2是两个独立的对象,那为什么它说它含糊不清......

请帮助......

班级订单......

@Entity (name = "orders")
public @Data
class Order {

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "orderID", unique = true, nullable = false)
    private int id;

    @Column
    private List<Item> items = new ArrayList<>();

    @Column(name = "orderDate", nullable = false)
    private String dateOrdered;

    public Order() {
    }
}

0 个答案:

没有答案