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; // 與用戶的關(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.生成訂單
public String createOrder() { // 將Order對(duì)象存入到數(shù)據(jù)庫(kù)中: // 封裝Order對(duì)象: Order order = new Order(); // 封裝總價(jià)---從購(gòu)物車的信息獲得. // 獲得購(gòu)物車: Cart cart = (Cart) ServletActionContext.getRequest().getSession() .getAttribute("cart"); // 判斷: if (cart == null) { this.addActionError("親!您還沒有購(gòu)物!請(qǐng)先去購(gòu)物!"); return "msg"; } // 設(shè)置所屬用戶: User existUser = (User) ServletActionContext.getRequest().getSession() .getAttribute("existUser"); if (existUser == null) { this.addActionError("親!您還沒有登錄!請(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ā)貨,沒有確認(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)物車清空了. cart.clearCart(); // 調(diào)用Service保存訂單的操作: orderService.save(order); // 將訂單存入到值棧中: ActionContext.getContext().getValueStack().set("order", order); // 頁(yè)面跳轉(zhuǎn): return "createOrderSuccess"; }
4.查詢我的訂單
? ?1.根據(jù)用戶的id查詢訂單
?
5.查詢某個(gè)訂單:
? ?1.跟單訂單id查詢訂單
?
本站聲明
本文內(nèi)容由網(wǎng)友自發(fā)貢獻(xiàn),版權(quán)歸原作者所有,本站不承擔(dān)相應(yīng)法律責(zé)任。如您發(fā)現(xiàn)有涉嫌抄襲侵權(quán)的內(nèi)容,請(qǐng)聯(lián)系admin@php.cn

熱AI工具

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

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

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Clothoff.io
AI脫衣機(jī)

Video Face Swap
使用我們完全免費(fèi)的人工智能換臉工具輕松在任何視頻中換臉!

熱門文章
指南:恒星刀片保存文件位置/保存文件丟失/不保存
4 周前
By DDD
Oguri Cap Build Guide |漂亮的德比志
2 周前
By Jack chen
Agnes Tachyon Build Guide |漂亮的德比志
2 周前
By Jack chen
沙丘:覺醒 - 高級(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集成開發(fā)環(huán)境

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

SublimeText3 Mac版
神級(jí)代碼編輯軟件(SublimeText3)