欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JAVAWEB实现简单的商城项目(一)实例代码解析

程序员文章站 2024-03-08 19:04:34
 一.项目功能结构 1.功能 2.实体 3.对应sql语句 create database shop; use shop; creat...

 一.项目功能结构

1.功能

JAVAWEB实现简单的商城项目(一)实例代码解析

2.实体

JAVAWEB实现简单的商城项目(一)实例代码解析

3.对应sql语句

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

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

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三个类.可以参开前面的博文,jsp通用分页框架

完整建立后如下

JAVAWEB实现简单的商城项目(一)实例代码解析

关于javaweb实现简单的商城项目就给大家介绍到这里,希望对大家有所帮助!