Table of Contents
Online mall 7--Order module
1.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;
Copy after login
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; // 与用户的关联关系 private User user; // 与订单项关联关系 private Set<OrderItem> orderItems = new HashSet<OrderItem>(); .... }
Copy after login
public class OrderItem { private Integer itemid; private Integer count; private Double subtotal; private Product product; private Order order; .... }
Copy after login
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()); // 封装状态 order.setState(1); // 1 未付款 2 已经付款,未发货 3.已经发货,没有确认收货 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"; }
Copy after login
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

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article
Assassin's Creed Shadows: Seashell Riddle Solution
3 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
2 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
3 weeks ago
By DDD
Assassin's Creed Shadows - How To Find The Blacksmith And Unlock Weapon And Armour Customisation
1 months ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
3 weeks ago
By DDD

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)

Hot Topics
CakePHP Tutorial
1389
52

