程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> javaweb實戰之商城項目開辟(一)

javaweb實戰之商城項目開辟(一)

編輯:關於JAVA

javaweb實戰之商城項目開辟(一)。本站提示廣大學習愛好者:(javaweb實戰之商城項目開辟(一))文章只能為提供參考,不一定能成為您想要的結果。以下是javaweb實戰之商城項目開辟(一)正文


一.項目功效構造

1.功效

2.實體

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三個類.

完全樹立後以下

本文是項目實戰的第一篇,以後還有更新,願望年夜家不要錯過。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved