我想知道是否有人可以在这里给我建议;我有一个应用程序,它有这样的类:
代码:
public class Order implements Serializable {
private int orderNo;
private int customerNo;
private date orderDate;
public int getOrderNo () {
return orderNo;
}
public int getCustomerNo () {
return customerNo;
}
public date getOrderDate () {
return orderDate;
}
// And so on with set methods.
}
public class OrderLine implements Serializable {
private int orderNo;
private int lineNo;
private int qty;
private int prodID;
// Get and set methods for each of the above.
public int getOrderNo () {
return orderNo;
}
public int getLineNo () {
return lineNo;
}
public int getQty () {
return qty;
}
public int prodID () {
return prodID;
}
// And so on with set methods.
}
这直接转化为关系表:
Order: orderno, customerNo, orderDate OrderLine: orderno, lineNo, qty, prodID
因此,每个类都直接转换为一个数据库表,其中每个属性都有 get 和 set 对。
现在我想知道的是,如果在 Java Web 应用程序中,这些类应该像上面那样还是更像这样,其中获取返回对象:
代码:
public class Order implements Serializable {
private int orderNo;
private Customer;
private date orderDate;
private ArrayList<OrderLine>lineItems;
public int getOrderNo () {
return orderNo;
}
public Customer getCustomer () {
return Customer;
}
public date getOrderDate () {
return orderDate;
}
public ArrayList<OrderLine> getOrderLines () {
return lineItems;
}
public OrderLine[] getOrderLines () {
return lineItems;
}
// And so on with set methods.
}
public class OrderLine implements Serializable {
private int orderNo;
private int lineNo;
private int qty;
private Product;
// Get and set methods for each of the above.
public int getOrderNo () {
return orderNo;
}
public int getLineNo () {
return lineNo;
}
public int getQty () {
return qty;
}
public int getProduct () {
return Product;
}
}
哪种方法更好?或者,只要处理数据的类正确执行并且系统高效运行,采用哪种方法真的很重要吗?
谢谢
摩根先生