1.建表:
CREATE TABLE `orders` ( `oid` int(11) NOT NULL AUTO_INCREMENT, `total` double DEFAULT NULL, `ordertime` datetime DEFAULT NULL, `state` int(11) DEFAULT NULL, `name` varchar(20) DEFAULT NULL, `addr` varchar(100) DEFAULT NULL, `phone` varchar(20) DEFAULT NULL, `uid` int(11) DEFAULT NULL, PRIMARY KEY (`oid`), KEY `FKC3DF62E5AA3D9C7` (`uid`), CONSTRAINT `FKC3DF62E5AA3D9C7` FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8; CREATE TABLE `orderitem` ( `itemid` int(11) NOT NULL AUTO_INCREMENT, `count` int(11) DEFAULT NULL, `subtotal` double DEFAULT NULL, `pid` int(11) DEFAULT NULL, `oid` int(11) DEFAULT NULL, PRIMARY KEY (`itemid`), KEY `FKE8B2AB6166C01961` (`oid`), KEY `FKE8B2AB6171DB7AE4` (`pid`), CONSTRAINT `FKE8B2AB6166C01961` FOREIGN KEY (`oid`) REFERENCES `orders` (`oid`), CONSTRAINT `FKE8B2AB6171DB7AE4` FOREIGN KEY (`pid`) REFERENCES `product` (`pid`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
?
?2.bean
public class Order { private Integer oid; private Double total; private Date ordertime; private String name; private String addr; private String phone; private Integer state; // 與用戶(hù)的關(guān)聯(lián)關(guān)系 private User user; // 與訂單項(xiàng)關(guān)聯(lián)關(guān)系 private Set<OrderItem> orderItems = new HashSet<OrderItem>(); .... }
?
public class OrderItem { private Integer itemid; private Integer count; private Double subtotal; private Product product; private Order order; .... }
3.產(chǎn)生訂單
public String createOrder() { // 將Order對(duì)象存入到數(shù)據(jù)庫(kù)中: // 封裝Order對(duì)象: Order order = new Order(); // 封裝總價(jià)---從購(gòu)物車(chē)的信息獲得. // 獲得購(gòu)物車(chē): Cart cart = (Cart) ServletActionContext.getRequest().getSession() .getAttribute("cart"); // 判斷: if (cart == null) { this.addActionError("親!您還沒(méi)有購(gòu)物!請(qǐng)先去購(gòu)物!"); return "msg"; } // 設(shè)置所屬用戶(hù): User existUser = (User) ServletActionContext.getRequest().getSession() .getAttribute("existUser"); if (existUser == null) { this.addActionError("親!您還沒(méi)有登錄!請(qǐng)先去登錄!"); return "msg"; } order.setUser(existUser); order.setTotal(cart.getTotal()); // 封裝時(shí)間 order.setOrdertime(new Date()); // 封裝狀態(tài) order.setState(1); // 1 未付款 2 已經(jīng)付款,未發(fā)貨 3.已經(jīng)發(fā)貨,沒(méi)有確認(rèn)收貨 4.訂單完成. // 為訂單設(shè)置訂單項(xiàng)集合: for (CartItem cartItem : cart.getCartItems()) { // 將購(gòu)物項(xiàng)的數(shù)據(jù)封裝到訂單項(xiàng)中. OrderItem orderItem = new OrderItem(); orderItem.setCount(cartItem.getCount()); orderItem.setSubtotal(cartItem.getSubtotal()); orderItem.setProduct(cartItem.getProduct()); orderItem.setOrder(order); // 放入訂單的集合: order.getOrderItems().add(orderItem); } // 購(gòu)物車(chē)清空了. cart.clearCart(); // 調(diào)用Service保存訂單的操作: orderService.save(order); // 將訂單存入到值棧中: ActionContext.getContext().getValueStack().set("order", order); // 頁(yè)面跳轉(zhuǎn): return "createOrderSuccess"; }
4.查詢(xún)我的訂單
? ?1.依照使用者的id查詢(xún)訂單
?
5.查詢(xún)某個(gè)訂單:
? ?1.跟單訂單id查詢(xún)訂單
?
本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool
免費(fèi)脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線(xiàn)上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門(mén)文章
指南:恆星刀片保存文件位置/保存文件丟失/不保存
4 週前
By DDD
Oguri Cap Build Guide |漂亮的德比志
2 週前
By Jack chen
Agnes Tachyon Build Guide |漂亮的德比志
2 週前
By Jack chen
沙丘:覺(jué)醒 - 高級(jí)行星學(xué)家Quest演練
4 週前
By Jack chen
約會(huì)一切:德克和哈珀關(guān)係指南
4 週前
By Jack chen

熱工具

記事本++7.3.1
好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境

Dreamweaver CS6
視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版
神級(jí)程式碼編輯軟體(SublimeText3)
