我有以下对象:
public class Customer {
private int id;
private String name;
private Collection orders;
public int getId() {return id;}
public void setId(int id) {this.id = id;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public Collection getOrders() {return orders;}
public void setOrders(Collection orders) {this.orders = orders;}
}
public class Order {
private int id;
private String item;
public int getId() {return id;}
public void setId(int id) {this.id = id;}
public String getItem() {return item;}
public void setItem(String item) {this.item = item;}
}
public class CustomerOrderDto {
private int customerId;
private String customerName;
private String orderId;
private String orderItem;
public int getCustomerId() {return customerId;}
public void setCustomerId(int customerId) {this.customerId = customerId;}
public String getName() {return name;}
public void setName(String name) {this.name = name;}
public String getOrderId() {return orderId;}
public void setOrderId(String orderId) {this.orderId = orderId;}
public String getOrderItem() {return orderItem;}
public void setOrderItem(String orderItem) {this.orderItem = orderItem;}
}所以如果我有一个有两个订单的Customer对象,结果将是一个两个CustomerOrderDto对象的列表。
我明显可以通过for循环来做到这一点,但我正在寻找使用Java流的更优雅的解决方案
我的背景是.NET,我可以很容易地用LINQ做到这一点,但这是我的第一个Java项目,我想看看我能否在这里做类似的事情。