后台:
类别管理(category)
添加
查看
商品管理
添加
查看
订单管理
查看未发货的订单
查看已发货的订单
数据库设计
create table category
(
id varchar(40) primary key,
name varchar(100) not null unique,
description varchar(255) not null
);
create table book
(
id varchar(40) primary key,
name varchar(100) not null unique,
author varchar(40) not null,
price double not null,
image varchar(255) not null,
description varchar(255) not null,
category_id varchar(40),
constraint category_id_FK foreign key(category_id) references category(id)
);
create table orders
(
id varchar(40) primary key,
ordertime datetime not null,
status boolean not null,
price double not null,
user_id varchar(40),
constraint user_id_FK foreign key(user_id) references user(id)
);
create table orderitem
(
id varchar(40) primary key,
quantity int not null,
price double not null,
order_id varchar(40),
book_id varchar(40),
constraint order_id_FK foreign key(order_id) references orders(id),
constraint book_id_FK foreign key(book_id) references book(id)
);
create table dbbackup
(
id varchar(40) primary key,
filename varchar(255) not null unique,
path varchar(255) not null,
backuptime datetime
);
前台:
1,左侧 类别:
分页数据
当第一次跳转到前台页面。分类页数据中category_id为空,点击分类时。category_id存到request域中。然后再点分页的页码,通过
¥{param.category_id}获取request域中的category_id。
2,右侧 商品信息
2.1,点击购买:
传一个bookid到bookservlet
bookservlet:servlice.addbook(bookid,cart);
BuniessService:
public void addbook(String bookid,Cart cart)
{
Book book = bdao.find(bookid);
cart.add(book);
}
Cart.java:
package cn.itcast.domain;
import java.util.LinkedHashMap;
import java.util.Map;
public class Cart {
private Map
String:书的ID,CartItem:购物车项(不要放book,因为你不可能只购买一本书)
private double price;
public void add(Book book){
CartItem item = map.get(book.getId());
if(item==null){
item = new CartItem();
item.setBook(book);
item.setQuantity(1);
map.put(book.getId(), item);
}else{
item.setQuantity(item.getQuantity()+1);
}
}
public Map
return map;
}
public void setMap(Map
this.map = map;
}
public double getPrice() {
double totalprice = 0;
for(Map.Entry
CartItem item = me.getValue();
totalprice += item.getPrice();
}
this.price = totalprice;
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
CartItem.java:
package cn.itcast.domain;
public class CartItem {
private Book book;
private int quantity;
private double price;
public Book getBook() {
return book;
}
public void setBook(Book book) {
this.book = book;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
this.price = this.book.getprice * this.quantity //当人家点击更新数量时
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}