Java Web simple mall project (1)
The project uses the paging framework of the previous blog, and mybatis, which focuses on mybatis.
I am a little confused. I don't know what to do. Alas, I don't want to do that much. It's right to learn it.
I. project function structure 1. Functions
2. Entity
3. corresponding SQL statement
Create database shop; use shop; create table user (id int (11) primary key auto_increment, username varchar (100), password varchar (100), nickname varchar (100 ), type int (5); insert into user VALUES (null, 'admin', '000000', 'admin', 1); create table address (id INT (10) primary key AUTO_INCREMENT, name VARCHAR (255), phone VARCHAR (100), postcode VARCHAR (100), user_id INT (10), constraint foreign key (user_id) REFERENCES user (id); insert into address VALUES (NULL, 'anhui Fuyang ', '000000', '000000', '1'); SELECT t1 .*, t2. * FROM address t1 left join user t2 ON t1.user _ id = t2.id where t1.user _ id = 1; create table orders (id int (11) primary key auto_increment, buy_date datetime, pay_date datetime, confirm_date datetime, status int (5), user_id int (11), address_id int (11), constraint foreign key (user_id) REFERENCES user (id ), constraint foreign key (address_id) REFERENCES address (id); create table category (id int (11) primary key auto_increment, name varchar (100 )); create table goods (id int (11) primary key auto_increment, name varchar (100), price double, intro text, img varchar (100), stock int (10 ), c_id int (10), constraint foreign key (c_id) REFERENCES category (id); create table goods_orders (id int (11) primary key auto_increment, goods_id int (10 ), orders_id int (10), constraint foreign key (goods_id) REFERENCES goods (id), constraint foreign key (orders_id) REFERENCES orders (id ));
Ii. Project Preparation 1. entity class implementation
Create the dao, filter, model, and util packages respectively, and implement real-world classes in the model. Here we use User. java as an example.
Note thatForeign database keysFor example, if the adress table has a foreign key user_id, you can directly give a User object in Adress. java and get the user together when getting the adress table.
User. java
Package com. model; import java. util. list;/*** Created by nl101 on 2016/2/22. */public class User {private int id; // id private String username; private String password; private String nickname; // nickname private int type; // 1 indicates the administrator, 2 indicates the private List of registered users.
addresses; public List
getAddresses() { return addresses; } public void setAddresses(List
addresses) { this.addresses = addresses; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getNickname() { return nickname; } public void setNickname(String nickname) { this.nickname = nickname; } public int getType() { return type; } public void setType(int type) { this.type = type; }}
Adress. java
Package com. model;/*** Created by nl101 on 2016/2/22. */public class Address {private int id; private String name; private String phone; private String postcode; // directly give the user object to replace user_id private User user; public int getId () {return id;} public void setId (int id) {this. id = id;} public String getName () {return name;} public void setName (String name) {this. name = name;} public String getPhone () {return phone;} public void setPhone (String phone) {this. phone = phone;} public String getPostcode () {return postcode;} public void setPostcode (String postcode) {this. postcode = postcode;} public User getUser () {return user;} public void setUser (User user User) {this. user = user ;}}
2. Paging Framework preparation
Pagination is mainly used to write pager. java, SystemContext. java, and SystemFilter. java. You can refer to the previous blog post and use the common pagination framework of jsp.
After the complete setup