Table of Contents
Online mall 7--Order module
Nov 30, 2016 pm 11:59 PM1.Create a table:
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; // 與用戶的關聯(lián)關系 private User user; // 與訂單項關聯(liá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. Generate order
public String createOrder() { // 將Order對象存入到數據庫中: // 封裝Order對象: Order order = new Order(); // 封裝總價---從購物車的信息獲得. // 獲得購物車: Cart cart = (Cart) ServletActionContext.getRequest().getSession() .getAttribute("cart"); // 判斷: if (cart == null) { this.addActionError("親!您還沒有購物!請先去購物!"); return "msg"; } // 設置所屬用戶: User existUser = (User) ServletActionContext.getRequest().getSession() .getAttribute("existUser"); if (existUser == null) { this.addActionError("親!您還沒有登錄!請先去登錄!"); return "msg"; } order.setUser(existUser); order.setTotal(cart.getTotal()); // 封裝時間 order.setOrdertime(new Date()); // 封裝狀態(tài) order.setState(1); // 1 未付款 2 已經付款,未發(fā)貨 3.已經發(fā)貨,沒有確認收貨 4.訂單完成. // 為訂單設置訂單項集合: for (CartItem cartItem : cart.getCartItems()) { // 將購物項的數據封裝到訂單項中. OrderItem orderItem = new OrderItem(); orderItem.setCount(cartItem.getCount()); orderItem.setSubtotal(cartItem.getSubtotal()); orderItem.setProduct(cartItem.getProduct()); orderItem.setOrder(order); // 放入訂單的集合: order.getOrderItems().add(orderItem); } // 購物車清空了. cart.clearCart(); // 調用Service保存訂單的操作: orderService.save(order); // 將訂單存入到值棧中: ActionContext.getContext().getValueStack().set("order", order); // 頁面跳轉: return "createOrderSuccess"; }
4. Check my order
1.Query the order based on the user’s id
5. Query an order:
1.Follow orderidQuery order
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Guide: Stellar Blade Save File Location/Save File Lost/Not Saving
4 weeks ago
By DDD
Oguri Cap Build Guide | A Pretty Derby Musume
2 weeks ago
By Jack chen
Agnes Tachyon Build Guide | A Pretty Derby Musume
1 weeks ago
By Jack chen
Dune: Awakening - Advanced Planetologist Quest Walkthrough
3 weeks ago
By Jack chen
Date Everything: Dirk And Harper Relationship Guide
4 weeks ago
By Jack chen

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
