准备如下用户表,订单表,订单明细表,商品表
用户表:user_id,user_name
订单表:order_id,order_no,user_id
订单明细表:orderdetail_id,order_id,product_id
商品表:product_id,product_name
实体类
package com.zns.domain;import java.util.List;public class User { private int userid; private String username; private Listorders; public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public List getOrders() { return orders; } public void setOrders(List orders) { this.orders = orders; } @Override public String toString() { return "User [userid=" + userid + ", username=" + username + ", orders=" + orders + "]"; }}
package com.zns.domain;import java.util.List;public class Order { private int orderid; private String orderno; private int userid; private User user; private ListorderDetails; public int getOrderid() { return orderid; } public void setOrderid(int orderid) { this.orderid = orderid; } public String getOrderno() { return orderno; } public void setOrderno(String orderno) { this.orderno = orderno; } public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public List getOrderDetails() { return orderDetails; } public void setOrderDetails(List orderDetails) { this.orderDetails = orderDetails; } @Override public String toString() { return "Order [orderid=" + orderid + ", orderno=" + orderno + ", userid=" + userid + ", user=" + user + ", orderDetails=" + orderDetails + "]"; }}
package com.zns.domain;public class OrderDetail { private int orderdetailid; private int orderid; private int productid; private Product product; public int getOrderdetailid() { return orderdetailid; } public void setOrderdetailid(int orderdetailid) { this.orderdetailid = orderdetailid; } public int getOrderid() { return orderid; } public void setOrderid(int orderid) { this.orderid = orderid; } public int getProductid() { return productid; } public void setProductid(int productid) { this.productid = productid; } public Product getProduct() { return product; } public void setProduct(Product product) { this.product = product; } @Override public String toString() { return "OrderDetail [orderdetailid=" + orderdetailid + ", orderid=" + orderid + ", productid=" + productid + ", product=" + product + "]"; }}
package com.zns.domain;public class Product { private int productid; private String productname; public int getProductid() { return productid; } public void setProductid(int productid) { this.productid = productid; } public String getProductname() { return productname; } public void setProductname(String productname) { this.productname = productname; } @Override public String toString() { return "Product [productid=" + productid + ", productname=" + productname + "]"; }}
Mybatis映射配置如下