国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
5. Query an order:" >5. Query an order:
Home php教程 php手冊(cè) Online mall 7--Order module

Online mall 7--Order module

Nov 30, 2016 pm 11:59 PM

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;

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. Generate order

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("親!您還沒(méi)有購(gòu)物!請(qǐng)先去購(gòu)物!");
		return "msg";
	}
	// 設(shè)置所屬用戶:
	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)物車清空了.
	cart.clearCart();
	// 調(diào)用Service保存訂單的操作:
	orderService.save(order);

	// 將訂單存入到值棧中:
	ActionContext.getContext().getValueStack().set("order", order);
	// 頁(yè)面跳轉(zhuǎn):
	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 AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)