(3)小项目

我用的软件是eclipse

用的服务器是tomcat9

使用的数据库软件是Navicat Lite(可以鼠标点)

架构:三层架构(MVC)

 

首先

你需要创建数据库,然后创建一张表(对象),里面要有属性

属性从我们的要实现的功能得到,

比如实现登入功能:需要账号,密码

 

结构:

 

 

 

这里我给代码,可以直接运行,还要数据(这个是放在edu.uc.bean)

 1 -- 1. Member
 2 
 3 DROP TABLE IF EXISTS Member;
 4 
 5 CREATE TABLE Member (
 6     `UserId` bigint(18) NOT NULL AUTO_INCREMENT comment '用户Id',
 7     `UserName` varchar(20) NOT NULL DEFAULT '' comment '账号',
 8     `UserPass` varchar(32) NOT NULL DEFAULT '' comment '密码',
 9     `NickName` varchar(20) NOT NULL DEFAULT '' comment '昵称',
10     `Email` varchar(32) NOT NULL DEFAULT '' comment '邮件',
11     `Mobile` varchar(20) NULL DEFAULT '' comment '手机',
12 
13     `MyId` varchar(50)  NULL DEFAULT '' comment 'myId',
14     `MyIdKey` varchar(50) NULL DEFAULT '' comment 'myIdKey',
15     `RegIp` varchar(50) NULL DEFAULT '' comment '注册IP',
16     `RegDate` datetime  NULL DEFAULT now() comment '注册时间',
17     `LastLoginIp` varchar(50) NULL DEFAULT '0' comment '最后登录IP',
18     `LastLoginTime` datetime  NULL comment '最后登录时间',
19     `Salt` varchar(6) NULL DEFAULT 'Liuvei' comment 'salt',
20     `Secques` varchar(8) NULL default '' comment 'secques',
21 
22     `Status` varchar(20) null DEFAULT '' comment '状态',
23     `IsDeleted` bigint(18) null DEFAULT 0 comment '是否删除',
24     `CreateBy` bigint(18) null DEFAULT 0 comment '创建用户',
25     `UpdateBy` bigint(18) null DEFAULT 0 comment '更新用户',
26     `CreateOn` datetime null DEFAULT now() comment '创建时间',
27     `UpdateOn` datetime null DEFAULT now() comment '更新时间',
28 
29     PRIMARY KEY(UserId)
30 ) comment '用户' character set UTF8;
31 
32 -- 为Member添加约束
33 ALTER TABLE Member
34 Add CONSTRAINT uq_Member_UserName Unique Key(UserName);
35 
36 ALTER TABLE Member
37 Add CONSTRAINT uq_Member_NickName Unique Key(NickName);
38 
39 ALTER TABLE Member
40 Add CONSTRAINT uq_Member_Email Unique Key(Email);
41 
42 
43 
44 
45 
46 -- init Member
47 TrunCate Table `Member`;
48 
49 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
50 Values ('1', 'admin', '123', '超管', 'admin@liuvei.com', '');
51 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
52 Values ('2', 'user', '123', '用户', 'user@liuvei.com', '');
53 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
54 Values ('3', 'guest', '123', '游客', 'guest@liuvei.com', '');
55 
56 
57 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
58 Values ('4', 'stu1', '123', '张三', 'stu1@liuvei.com', 'Teacher');
59 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
60 Values ('5', 'stu2', '123', '李四', 'stu2@liuvei.com', 'Teacher');
61 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
62 Values ('6', 'stu3', '123', '王五', 'stu3@liuvei.com', 'Teacher');
63 
64 
65 
66 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
67 Values ('7', 't1', '123', '刘明', 't1@liuvei.com', 'Student');
68 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
69 Values ('8', 't2', '123', '李玉', 't2@liuvei.com', 'Student');
70 Insert Into `member`(`UserId`, `Username`, `Userpass`, `Nickname`, `Email`, `Status`)
71 Values ('9', 't3', '123', '周生', 't3@liuvei.com', 'Student');

 

 

 

然后

你需要eclipse创建javaweb项目(可以运行tomcat的)

创建好后:

你需要对照数据库的属性,创建实体类(Member),并且导入自己的get/set方法

  1 package edu.uc.bean;
  2 
  3 public class Member implements java.io.Serializable {
  4 
  5     /**
  6      * 
  7      */
  8     private static final long serialVersionUID = 1L;
  9 
 10     private long userId;
 11     private String userName;
 12     private String userPass;
 13     private String nickName;
 14     private String email;
 15     private String mobile;
 16     private String myId;
 17     private String myIdkey;
 18     private String regIp;
 19     private java.util.Date regDate;
 20     private String lastLoginIp;
 21     private java.util.Date lastLoginTime;
 22     private String salt;
 23     private String secques;
 24     private String status;
 25     private String remark;
 26     private Long sortNum;
 27     
 28     
 29     
 30     public String getRemark() {
 31         return remark;
 32     }
 33     
 34     public void setRemark(String remark) {
 35         this.remark = remark;
 36     }
 37 
 38     public Long getSortNum() {
 39         return sortNum;
 40     }
 41     public void setSortNum(Long sortNum) {
 42         this.sortNum = sortNum;
 43     }
 44 
 45     private Long isDeleted;
 46     private Long createBy;
 47     private Long updateBy;
 48     private java.util.Date createOn;
 49     private java.util.Date updateOn;
 50     public long getUserId() {
 51         return userId;
 52     }
 53     public void setUserId(long userId) {
 54         this.userId = userId;
 55     }
 56     public String getUserName() {
 57         return userName;
 58     }
 59     public void setUserName(String userName) {
 60         this.userName = userName;
 61     }
 62     public String getUserPass() {
 63         return userPass;
 64     }
 65     public void setUserPass(String userPass) {
 66         this.userPass = userPass;
 67     }
 68     public String getNickName() {
 69         return nickName;
 70     }
 71     public void setNickName(String nickName) {
 72         this.nickName = nickName;
 73     }
 74     public String getEmail() {
 75         return email;
 76     }
 77     public void setEmail(String email) {
 78         this.email = email;
 79     }
 80     public String getMobile() {
 81         return mobile;
 82     }
 83     public void setMobile(String mobile) {
 84         this.mobile = mobile;
 85     }
 86     public String getMyId() {
 87         return myId;
 88     }
 89     public void setMyId(String myId) {
 90         this.myId = myId;
 91     }
 92     public String getMyIdkey() {
 93         return myIdkey;
 94     }
 95     public void setMyIdkey(String myIdkey) {
 96         this.myIdkey = myIdkey;
 97     }
 98     public String getRegIp() {
 99         return regIp;
100     }
101     public void setRegIp(String regIp) {
102         this.regIp = regIp;
103     }
104     public java.util.Date getRegDate() {
105         return regDate;
106     }
107     public void setRegDate(java.util.Date regDate) {
108         this.regDate = regDate;
109     }
110     public String getLastLoginIp() {
111         return lastLoginIp;
112     }
113     public void setLastLoginIp(String lastLoginIp) {
114         this.lastLoginIp = lastLoginIp;
115     }
116     public java.util.Date getLastLoginTime() {
117         return lastLoginTime;
118     }
119     public void setLastLoginTime(java.util.Date lastLoginTime) {
120         this.lastLoginTime = lastLoginTime;
121     }
122     public String getSalt() {
123         return salt;
124     }
125     public void setSalt(String salt) {
126         this.salt = salt;
127     }
128     public String getSecques() {
129         return secques;
130     }
131     public void setSecques(String secques) {
132         this.secques = secques;
133     }
134     public String getStatus() {
135         return status;
136     }
137     public void setStatus(String status) {
138         this.status = status;
139     }
140     public Long getIsDeleted() {
141         return isDeleted;
142     }
143     public void setIsDeleted(Long isDeleted) {
144         this.isDeleted = isDeleted;
145     }
146     public Long getCreateBy() {
147         return createBy;
148     }
149     public void setCreateBy(Long createBy) {
150         this.createBy = createBy;
151     }
152     public Long getUpdateBy() {
153         return updateBy;
154     }
155     public void setUpdateBy(Long updateBy) {
156         this.updateBy = updateBy;
157     }
158     public java.util.Date getCreateOn() {
159         return createOn;
160     }
161     public void setCreateOn(java.util.Date createOn) {
162         this.createOn = createOn;
163     }
164     public java.util.Date getUpdateOn() {
165         return updateOn;
166     }
167     public void setUpdateOn(java.util.Date updateOn) {
168         this.updateOn = updateOn;
169     }
170     
171     
172     
173     
174 }
View Code

 

恭喜你第一步完成了

posted @ 2020-04-29 20:57  赚钱买个打印机  阅读(178)  评论(0编辑  收藏  举报