1.查询所有订单信息

1.1查看显示订单的前端页面需要哪些订单信息

根据下面的orders-list.jsp页面的部分代码可以知道订单的信息表中不仅需要订单的id,orderNum,orderTimeStr,orderStatusStr,还需要的产品的productName,productPrice。因此在查询订单的信息时需要将该订单的产品信息也要查询出来并封装到Orders类中。

 1 <tbody>
 2 
 3 
 4                                     <c:forEach items="${ordersList}" var="orders">
 5 
 6                                         <tr>
 7                                             <td><input name="ids" type="checkbox"></td>
 8                                             <td>${orders.id }</td>
 9                                             <td>${orders.orderNum }</td>
10                                             <td>${orders.product.productName }</td>
11                                             <td>${orders.product.productPrice }</td>
12                                             <td>${orders.orderTimeStr }</td>
13                                             <td class="text-center">${orders.orderStatusStr }</td>
14                                             <td class="text-center">
15                                                 <button type="button" class="btn bg-olive btn-xs">订单</button>
16                                                 <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/orders/findById.do?id=${orders.id}'">详情</button>
17                                                 <button type="button" class="btn bg-olive btn-xs">编辑</button>
18                                             </td>
19                                         </tr>
20                                     </c:forEach>
21                                 </tbody>

1.2在domain包下新建Orders类

该类中不仅包含orders表中基本的字段信息,还新增了orderTimeStr,orderStatusStr,product,travellers,member。

由于Date类型的无法在前端页面正常显示因此新增了orderTimeStr类,在get方法中将orderTime转换成字符串形式。由于orders表中orderStatus只是0或1,而前端页面需要具体的订单状态“关闭”或“开启”,因此在get方法中将orderStatus的0或1转换成orderStatusStr的“关闭”或开启。product是根据orders表中的productId从product表中查出的,并将其封装到该类的product中。

  1 package club.nipengfei.domain;
  2 
  3 import club.nipengfei.utils.DateUtils;
  4 
  5 import java.util.Date;
  6 import java.util.List;
  7 
  8 public class Orders {
  9     private String id;
 10     private String orderNum;
 11     private Date orderTime;
 12     private String orderTimeStr;
 13     private int orderStatus;
 14     private String orderStatusStr;
 15     private int peopleCount;
 16     private Product product;
 17     private List<Traveller> travellers;
 18     private Member member;
 19     private Integer payType;
 20 
 21     public String getOrderStatusStr() {
 22         if (orderStatus == 0){
 23             orderStatusStr = "未支付";
 24         }
 25         if (orderStatus == 1){
 26             orderStatusStr = "已支付";
 27         }
 28         return orderStatusStr;
 29     }
 30 
 31     public void setOrderStatusStr(String orderStatusStr) {
 32         this.orderStatusStr = orderStatusStr;
 33     }
 34 
 35     private String payTypeStr;
 36     private String orderDesc;
 37 
 38     public String getId() {
 39         return id;
 40     }
 41 
 42     public void setId(String id) {
 43         this.id = id;
 44     }
 45 
 46     public String getOrderNum() {
 47         return orderNum;
 48     }
 49 
 50     public void setOrderNum(String orderNum) {
 51         this.orderNum = orderNum;
 52     }
 53 
 54     public Date getOrderTime() {
 55         return orderTime;
 56     }
 57 
 58     public void setOrderTime(Date orderTime) {
 59         this.orderTime = orderTime;
 60     }
 61 
 62     public String getOrderTimeStr() {
 63         if (orderTime != null){
 64             orderTimeStr = DateUtils.date2String(orderTime,"yyyy-MM-dd HH:mm");
 65         }
 66         return orderTimeStr;
 67     }
 68 
 69     public void setOrderTimeStr(String orderTimeStr) {
 70         this.orderTimeStr = orderTimeStr;
 71     }
 72 
 73     public int getOrderStatus() {
 74         return orderStatus;
 75     }
 76 
 77     public void setOrderStatus(int orderStatus) {
 78         this.orderStatus = orderStatus;
 79     }
 80 
 81     public int getPeopleCount() {
 82         return peopleCount;
 83     }
 84 
 85     public void setPeopleCount(int peopleCount) {
 86         this.peopleCount = peopleCount;
 87     }
 88 
 89     public Product getProduct() {
 90         return product;
 91     }
 92 
 93     public void setProduct(Product product) {
 94         this.product = product;
 95     }
 96 
 97     public List<Traveller> getTravellers() {
 98         return travellers;
 99     }
100 
101     public void setTravellers(List<Traveller> travellers) {
102         this.travellers = travellers;
103     }
104 
105     public Member getMember() {
106         return member;
107     }
108 
109     public void setMember(Member member) {
110         this.member = member;
111     }
112 
113     public Integer getPayType() {
114         return payType;
115     }
116 
117     public void setPayType(Integer payType) {
118         this.payType = payType;
119     }
120 
121     public String getPayTypeStr() {
122         if (payType != null){
123             if (payType == 0){
124                 payTypeStr = "支付宝";
125             }else if (payType == 1){
126                 payTypeStr = "微信";
127             }else if (payType == 2){
128                 payTypeStr = "其它";
129             }
130         }
131         return payTypeStr;
132     }
133 
134     public void setPayTypeStr(String payTypeStr) {
135         this.payTypeStr = payTypeStr;
136     }
137 
138     public String getOrderDesc() {
139         return orderDesc;
140     }
141 
142     public void setOrderDesc(String orderDesc) {
143         this.orderDesc = orderDesc;
144     }
145 }
View Code 

相关文章: