服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - JAVA教程 - javaweb实战之商城项目开发(一)

javaweb实战之商城项目开发(一)

2020-04-03 14:35茶饮月 JAVA教程

这篇文章主要针对javaweb商城项目开发进行实战演习,对javaweb商城项目开发进行详细分析,感兴趣的小伙伴们可以参考一下

一.项目功能结构

1.功能

javaweb实战之商城项目开发(一)

2.实体

javaweb实战之商城项目开发(一)

3.对应sql语句

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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','7946521','管理员',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 ,'安徽阜阳','1234567890','236000','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)
);

二.项目准备

1.实体类实现

分别建立dao,filter,model,util的包,并在model中实现实体类,这里以User.java为例.

注意对于数据库中外键,比如adress表中有外键user_id,那么在Adress.java中就可以直接给个User对象,在取adress表的时候就把user一并取出来.

User.java

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;//昵称
 private int type;//1表示管理员,2表示注册用户
 
 private List<Address> addresses;
 
 public List<Address> getAddresses() {
  return addresses;
 }
 
 public void setAddresses(List<Address> 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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
 //直接给user对象,来代替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) {
  this.user = user;
 }
}

2.分页框架准备

分页主要是写pager.java和SystemContext.java以及SystemFilter.java三个类.

完整建立后如下

javaweb实战之商城项目开发(一)

本文是项目实战的第一篇,之后还有更新,希望大家不要错过。

延伸 · 阅读

精彩推荐