smdms超市訂單管理系統之登錄功能
- 2022 年 4 月 4 日
- 筆記
- smbms超市訂單管理系統
一、超市訂單管理系統準備階段
- Supermarket order management system
-
創建數據庫
-
數據庫代碼放置如下
點擊查看數據庫address代碼
CREATE TABLE `smbms_address` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主鍵',
`contact` varchar(15) DEFAULT NULL COMMENT '聯繫人姓名',
`addressDesc` varchar(50) DEFAULT NULL COMMENT '收貨地址',
`postCode` varchar(15) DEFAULT NULL COMMENT '郵編',
`tel` int(20) DEFAULT NULL COMMENT '聯繫人電話',
`createdBy` varchar(20) DEFAULT NULL COMMENT '創建者',
`creationDate` datetime DEFAULT NULL COMMENT '創建時間',
`modifyBy` bigint(20) DEFAULT NULL COMMENT '修改者',
`modifyDate` datetime DEFAULT NULL COMMENT '修改時間',
`userId` bigint(20) DEFAULT NULL COMMENT '用戶ID',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `smbms_address` VALUES (1, '王麗', '北京市東城區東交民巷44號', '100010', '13678789999', 1, '2016-04-13 00:00:00', NULL, NULL, 1);
INSERT INTO `smbms_address` VALUES (2, '張紅麗', '北京市海淀區丹棱街3號', '100000', '18567672312', 1, '2016-04-13 00:00:00', NULL, NULL, 1);
INSERT INTO `smbms_address` VALUES (3, '任志強', '北京市東城區美術館后街23號', '100021', '13387906742', 1, '2016-04-13 00:00:00', NULL, NULL, 1);
INSERT INTO `smbms_address` VALUES (4, '曹穎', '北京市朝陽區朝陽門南大街14號', '100053', '13568902323', 1, '2016-04-13 00:00:00', NULL, NULL, 2);
INSERT INTO `smbms_address` VALUES (5, '李慧', '北京市西城區三里河路南三巷3號', '100032', '18032356666', 1, '2016-04-13 00:00:00', NULL, NULL, 3);
INSERT INTO `smbms_address` VALUES (6, '王國強', '北京市順義區高麗營鎮金馬工業區18號', '100061', '13787882222', 1, '2016-04-13 00:00:00', NULL, NULL, 3);
點擊查看數據庫bill代碼
CREATE TABLE `smbms_bill` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`billCode` varchar(30) DEFAULT NULL COMMENT '賬單編碼',
`productName` varchar(20) DEFAULT NULL COMMENT '商品名稱',
`productDesc` varchar(50) DEFAULT NULL COMMENT '商品描述',
`productUnit` varchar(60) DEFAULT NULL COMMENT '商品單位',
`productCount` decimal(20,2) DEFAULT NULL COMMENT '商品數量',
`totalPrice` decimal(20,2) DEFAULT NULL COMMENT '總金額',
`isPayment` int(10) DEFAULT NULL COMMENT '是否支付',
`createdBy` bigint(20) DEFAULT NULL COMMENT '創建者',
`creationDate` datetime DEFAULT NULL COMMENT '創建時間',
`modifyBy` bigint(20) DEFAULT NULL COMMENT '更新者',
`modifyDate` datetime DEFAULT NULL COMMENT '更新時間',
`providerId` int(10) DEFAULT NULL COMMENT '提供者id',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `smbms_bill` VALUES (2, 'BILL2016_002', '香皂、肥皂、藥皂', '日用品-皂類', '塊', 1000.00, 10000.00, 2, 1, '2016-03-23 04:20:40', NULL, NULL, 13);
INSERT INTO `smbms_bill` VALUES (3, 'BILL2016_003', '大豆油', '食品-食用油', '斤', 300.00, 5890.00, 2, 1, '2014-12-14 13:02:03', NULL, NULL, 6);
INSERT INTO `smbms_bill` VALUES (4, 'BILL2016_004', '橄欖油', '食品-進口食用油', '斤', 200.00, 9800.00, 2, 1, '2013-10-10 03:12:13', NULL, NULL, 7);
INSERT INTO `smbms_bill` VALUES (5, 'BILL2016_005', '洗潔精', '日用品-廚房清潔', '瓶', 500.00, 7000.00, 2, 1, '2014-12-14 13:02:03', NULL, NULL, 9);
INSERT INTO `smbms_bill` VALUES (6, 'BILL2016_006', '美國大杏仁', '食品-堅果', '袋', 300.00, 5000.00, 2, 1, '2016-04-14 06:08:09', NULL, NULL, 4);
INSERT INTO `smbms_bill` VALUES (7, 'BILL2016_007', '沐浴液、精油', '日用品-沐浴類', '瓶', 500.00, 23000.00, 1, 1, '2016-07-22 10:10:22', NULL, NULL, 14);
INSERT INTO `smbms_bill` VALUES (8, 'BILL2016_008', '不鏽鋼盤碗', '日用品-廚房用具', '個', 600.00, 6000.00, 2, 1, '2016-04-14 05:12:13', NULL, NULL, 14);
INSERT INTO `smbms_bill` VALUES (9, 'BILL2016_009', '塑料杯', '日用品-杯子', '個', 350.00, 1750.00, 2, 1, '2016-02-04 11:40:20', NULL, NULL, 14);
INSERT INTO `smbms_bill` VALUES (10, 'BILL2016_010', '豆瓣醬', '食品-調料', '瓶', 200.00, 2000.00, 2, 1, '2013-10-29 05:07:03', NULL, NULL, 8);
INSERT INTO `smbms_bill` VALUES (11, 'BILL2016_011', '海之藍', '飲料-國酒', '瓶', 50.00, 10000.00, 1, 1, '2016-04-14 16:16:00', NULL, NULL, 1);
INSERT INTO `smbms_bill` VALUES (12, 'BILL2016_012', '芝華士', '飲料-洋酒', '瓶', 20.00, 6000.00, 1, 1, '2016-09-09 17:00:00', NULL, NULL, 1);
INSERT INTO `smbms_bill` VALUES (13, 'BILL2016_013', '長城紅葡萄酒', '飲料-紅酒', '瓶', 60.00, 800.00, 2, 1, '2016-11-14 15:23:00', NULL, NULL, 1);
INSERT INTO `smbms_bill` VALUES (14, 'BILL2016_014', '泰國香米', '食品-大米', '斤', 400.00, 5000.00, 2, 1, '2016-10-09 15:20:00', NULL, NULL, 3);
INSERT INTO `smbms_bill` VALUES (15, 'BILL2016_015', '東北大米', '食品-大米', '斤', 600.00, 4000.00, 2, 1, '2016-11-14 14:00:00', NULL, NULL, 3);
INSERT INTO `smbms_bill` VALUES (16, 'BILL2016_016', '可口可樂', '飲料', '瓶', 2000.00, 6000.00, 2, 1, '2012-03-27 13:03:01', NULL, NULL, 2);
INSERT INTO `smbms_bill` VALUES (17, 'BILL2016_017', '脈動', '飲料', '瓶', 1500.00, 4500.00, 2, 1, '2016-05-10 12:00:00', NULL, NULL, 2);
INSERT INTO `smbms_bill` VALUES (18, 'BILL2016_018', '哇哈哈', '飲料', '瓶', 2000.00, 4000.00, 2, 1, '2015-11-24 15:12:03', NULL, NULL, 2);
點擊查看數據庫provider代碼
CREATE TABLE `smbms_provider` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`proCode` varchar(15) DEFAULT NULL COMMENT '供應商編碼',
`proName` varchar(15) DEFAULT NULL COMMENT '供應商名稱',
`proDesc` varchar(50) DEFAULT NULL COMMENT '供應商描述',
`proContact` varchar(15) DEFAULT NULL COMMENT '供應商聯繫人',
`proPhone` varchar(20) DEFAULT NULL COMMENT '供應商電話',
`userAddress` varchar(30) DEFAULT NULL COMMENT '供應商地址',
`userFax` varchar(20) DEFAULT NULL COMMENT '供應商傳真',
`createdBy` bigint(20) DEFAULT NULL COMMENT '創建者',
`creationDate` datetime DEFAULT NULL COMMENT '創建時間',
`modifyBy` bigint(20) DEFAULT NULL COMMENT '更新者',
`modifyDate` datetime DEFAULT NULL COMMENT '更新時間',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `smbms_provider` VALUES (1, 'BJ_GYS001', '北京三木堂商貿有限公司', '長期合作夥伴,主營產品:茅台、五糧液、郎酒、酒鬼酒、瀘州老窖、賴茅酒、法國紅酒等', '張國強', '13566667777', '北京市丰台區育芳園北路', '010-58858787', 1, '2013-03-21 16:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (2, 'HB_GYS001', '石家莊帥益食品貿易有限公司', '長期合作夥伴,主營產品:飲料、水飲料、植物蛋白飲料、休閑食品、果汁飲料、功能飲料等', '王軍', '13309094212', '河北省石家莊新華區', '0311-67738876', 1, '2016-04-13 04:20:40', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (3, 'GZ_GYS001', '深圳市泰香米業有限公司', '初次合作夥伴,主營產品:良記金輪米,龍輪香米等', '鄭程瀚', '13402013312', '廣東省深圳市福田區深南大道6006華豐大廈', '0755-67776212', 1, '2014-03-21 16:56:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (4, 'GZ_GYS002', '深圳市喜來客商貿有限公司', '長期合作夥伴,主營產品:堅果炒貨.果脯蜜餞.天然花茶.營養豆豆.特色美食.進口食品.海味零食.肉脯肉', '林妮', '18599897645', '廣東省深圳市福龍工業區B2棟3樓西', '0755-67772341', 1, '2013-03-22 16:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (5, 'JS_GYS001', '興化佳美調味品廠', '長期合作夥伴,主營產品:天然香辛料、雞精、複合調味料', '徐國洋', '13754444221', '江蘇省興化市林湖工業區', '0523-21299098', 1, '2015-11-22 16:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (6, 'BJ_GYS002', '北京納福爾食用油有限公司', '長期合作夥伴,主營產品:山茶油、大豆油、花生油、橄欖油等', '馬鶯', '13422235678', '北京市朝陽區珠江帝景1號樓', '010-588634233', 1, '2012-03-21 17:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (7, 'BJ_GYS003', '北京國糧食用油有限公司', '初次合作夥伴,主營產品:花生油、大豆油、小磨油等', '王馳', '13344441135', '北京大興青雲店開發區', '010-588134111', 1, '2016-04-13 00:00:00', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (8, 'ZJ_GYS001', '慈溪市廣和綠色食品廠', '長期合作夥伴,主營產品:豆瓣醬、黃豆醬、甜麵醬,辣椒,大蒜等農產品', '薛聖丹', '18099953223', '浙江省寧波市慈溪周巷小安村', '0574-34449090', 1, '2013-11-21 06:02:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (9, 'GX_GYS001', '優百商貿有限公司', '長期合作夥伴,主營產品:日化產品', '李立國', '13323566543', '廣西南寧市秀廂大道42-1號', '0771-98861134', 1, '2013-03-21 19:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (10, 'JS_GYS002', '南京火頭軍信息技術有限公司', '長期合作夥伴,主營產品:不鏽鋼廚具等', '陳女士', '13098992113', '江蘇省南京市浦口區浦口大道1號新城總部大廈A座903室', '025-86223345', 1, '2013-03-25 16:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (11, 'GZ_GYS003', '廣州市白雲區美星五金製品廠', '長期合作夥伴,主營產品:海綿床墊、坐墊、靠墊、海綿枕頭、頭枕等', '梁天', '13562276775', '廣州市白雲區鍾落潭鎮福龍路20號', '020-85542231', 1, '2016-12-21 06:12:17', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (12, 'BJ_GYS004', '北京隆盛日化科技', '長期合作夥伴,主營產品:日化環保清洗劑,家居洗滌專賣、洗滌用品網、牆體除霉劑、牆面黴菌清除劑等', '孫欣', '13689865678', '北京市大興區舊宮', '010-35576786', 1, '2014-11-21 12:51:11', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (13, 'SD_GYS001', '山東豪克華光聯合發展有限公司', '長期合作夥伴,主營產品:洗衣皂、洗衣粉、洗衣液、洗潔精、消殺類、香皂等', '吳洪轉', '13245468787', '山東濟陽濟北工業區仁和街21號', '0531-53362445', 1, '2015-01-28 10:52:07', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (14, 'JS_GYS003', '無錫喜源坤商行', '長期合作夥伴,主營產品:日化品批銷', '周一清', '18567674532', '江蘇無錫盛岸西路', '0510-32274422', 1, '2016-04-23 11:11:11', NULL, NULL);
INSERT INTO `smbms_provider` VALUES (15, 'ZJ_GYS002', '樂擺日用品廠', '長期合作夥伴,主營產品:各種中、高檔塑料杯,塑料樂扣水杯(密封杯)、保鮮杯(保鮮盒)、廣告杯、禮品杯', '王世傑', '13212331567', '浙江省金華市義烏市義東路', '0579-34452321', 1, '2016-08-22 10:01:30', NULL, NULL);
點擊查看數據庫role代碼
CREATE TABLE `smbms_role` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`roleCode` varchar(30) DEFAULT NULL COMMENT '角色編碼',
`roleName` varchar(15) DEFAULT NULL COMMENT '角色名稱',
`createdBy` bigint(20) DEFAULT NULL COMMENT '創建者',
`creationDate` datetime DEFAULT NULL COMMENT '創建時間',
`modifyBy` bigint(20) DEFAULT NULL COMMENT '更新者',
`modifyDate` datetime DEFAULT NULL COMMENT '更新時間',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `smbms_role` VALUES (1, 'SMBMS_ADMIN', '系統管理員', 1, '2016-04-13 00:00:00', NULL, NULL);
INSERT INTO `smbms_role` VALUES (2, 'SMBMS_MANAGER', '經理', 1, '2016-04-13 00:00:00', NULL, NULL);
INSERT INTO `smbms_role` VALUES (3, 'SMBMS_EMPLOYEE', '普通員工', 1, '2016-04-13 00:00:00', NULL, NULL);
點擊查看數據庫user代碼
CREATE TABLE `smbms_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
`userCode` varchar(15) DEFAULT NULL COMMENT '用戶編碼',
`userName` varchar(15) DEFAULT NULL COMMENT '用戶名字',
`userPassword` varchar(20) DEFAULT NULL COMMENT '用戶密碼',
`gender` int(10) DEFAULT NULL COMMENT '性別',
`birthday` date DEFAULT NULL COMMENT '出生日期',
`phone` varchar(20) DEFAULT NULL COMMENT '電話',
`address` varchar(30) DEFAULT NULL COMMENT '地址',
`userRole` bigint(20) DEFAULT NULL COMMENT '用戶角色',
`createdBy` bigint(20) DEFAULT NULL COMMENT '創建者',
`creationDate` datetime DEFAULT NULL COMMENT '創建時間',
`modifyBy` bigint(20) DEFAULT NULL COMMENT '更新者',
`modifyDate` datetime DEFAULT NULL COMMENT '更新時間',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `smbms_user` VALUES (1, 'admin', '111', '111111', 1, '2021-04-22', '13688889999', '北京市海淀區成府路207號', 3, 1, '2013-03-21 16:52:07', 1, '2021-04-22 17:43:02');
INSERT INTO `smbms_user` VALUES (2, 'liming', '李明', '0000000', 2, '1983-12-10', '13688884457', '北京市東城區前門東大街9號', 2, 1, '2014-12-31 19:52:09', NULL, NULL);
INSERT INTO `smbms_user` VALUES (5, 'hanlubiao', '韓路彪', '0000000', 2, '1984-06-05', '18567542321', '北京市朝陽區北辰中心12號', 2, 1, '2014-12-31 19:52:09', NULL, NULL);
INSERT INTO `smbms_user` VALUES (6, 'zhanghua', '張華', '0000000', 1, '1983-06-15', '13544561111', '北京市海淀區學院路61號', 3, 1, '2013-02-11 10:51:17', NULL, NULL);
INSERT INTO `smbms_user` VALUES (7, 'wangyang', '王洋', '0000000', 2, '1982-12-31', '13444561124', '北京市海淀區西二旗輝煌國際16層', 3, 1, '2014-06-11 19:09:07', NULL, NULL);
INSERT INTO `smbms_user` VALUES (8, 'zhaoyan', '趙燕', '0000000', 2, '2021-04-22', '18098764545', '北京市海淀區回龍觀小區10號樓', 2, 1, '2016-04-21 13:54:07', 1, '2021-04-22 17:56:11');
INSERT INTO `smbms_user` VALUES (10, 'sunlei', '孫磊', '0000000', 2, '1981-01-04', '13387676765', '北京市朝陽區管庄新月小區12樓', 3, 1, '2015-05-06 10:52:07', NULL, NULL);
INSERT INTO `smbms_user` VALUES (11, 'sunxing', '孫興', '0000000', 2, '1978-03-12', '13367890900', '北京市朝陽區建國門南大街10號', 3, 1, '2016-11-09 16:51:17', NULL, NULL);
INSERT INTO `smbms_user` VALUES (12, 'zhangchen', '張晨', '0000000', 1, '1986-03-28', '18098765434', '朝陽區管庄路口北柏林愛樂三期13號樓', 3, 1, '2016-08-09 05:52:37', 1, '2016-04-14 14:15:36');
INSERT INTO `smbms_user` VALUES (13, 'dengchao', '鄧超', '0000000', 2, '1981-11-04', '13689674534', '北京市海淀區北航家屬院10號樓', 3, 1, '2016-07-11 08:02:47', NULL, NULL);
INSERT INTO `smbms_user` VALUES (15, 'zhaomin', '趙敏', '0000000', 1, '1987-12-04', '18099897657', '北京市昌平區天通苑3區12號樓', 2, 1, '2015-09-12 12:02:12', NULL, NULL);
- 當數據庫配置完以後我們開始idea,創建一個Maven Webapp模板項目
- 然後開始配置Tomcat服務器
- 在pom.xml中導入項目依賴的jar包
點擊查看代碼
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency><!-- servlet包 -->
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency><!-- jstl包 -->
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<dependency><!-- jsp包 -->
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency><!-- 數據庫包 -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
二、進入idea開始編碼
- 首先編寫我們的實體類pojo,數據庫表中的信息與之對應。
點擊User類代碼
package pojo;
import java.util.Date;
public class User {
private Integer id; //id
private String userCode; //用戶編碼
private String userName; //用戶名字
private String userPassword; //用戶密碼
private Integer gender; //性別
private Date birthday; //出生日期
private String phone; //手機號
private String address; //地址
private Integer userRole; //用戶角色
private Integer createBy; //創建者
private Date creationDate; //創建時間
private Integer modifyBy; //更新者
private Date modifyDate; //更新時間
private Integer age; //年齡
private String userRoleName; //用戶角色名字
public Integer getAge() {
Date date = new Date();
Integer age = date.getYear() - birthday.getYear();
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getUserRoleName() {
return userRoleName;
}
public void setUserRoleName(String userRoleName) {
this.userRoleName = userRoleName;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUserCode() {
return userCode;
}
public void setUserCode(String userCode) {
this.userCode = userCode;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public Integer getGender() {
return gender;
}
public void setGender(Integer gender) {
this.gender = gender;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public Integer getUserRole() {
return userRole;
}
public void setUserRole(Integer userRole) {
this.userRole = userRole;
}
public Integer getCreateBy() {
return createBy;
}
public void setCreateBy(Integer createBy) {
this.createBy = createBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
點擊Role類代碼
package pojo;
import java.util.Date;
public class Role {
private Integer id; //id
private String roleCode; //角色編碼
private String roleName; //角色名字
private Integer createdBy; //創建者
private Date creationDate; //創建時間
private Integer modifyBy; //更新者
private Date modifyDate; //更新時間
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getRoleCode() {
return roleCode;
}
public void setRoleCode(String roleCode) {
this.roleCode = roleCode;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
點擊Provider代碼
package pojo;
import java.util.Date;
public class Provider {
private Integer id; //id
private String proCode; //供應商編碼
private String proName; //供應商名字
private String proDesc; //供應商查詢
private String proContact; //供應商聯繫人
private String proPhone; //供應商手機
private String proAddress; //供應商地址
private String proFax; //供應商傳真
private Integer createdBy; //創建者
private Date creationDate; //創建時間
private Integer modifyBy; //更新者
private Date modifyDate; //更新時間
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProCode() {
return proCode;
}
public void setProCode(String proCode) {
this.proCode = proCode;
}
public String getProName() {
return proName;
}
public void setProName(String proName) {
this.proName = proName;
}
public String getProDesc() {
return proDesc;
}
public void setProDesc(String proDesc) {
this.proDesc = proDesc;
}
public String getProContact() {
return proContact;
}
public void setProContact(String proContact) {
this.proContact = proContact;
}
public String getProPhone() {
return proPhone;
}
public void setProPhone(String proPhone) {
this.proPhone = proPhone;
}
public String getProAddress() {
return proAddress;
}
public void setProAddress(String proAddress) {
this.proAddress = proAddress;
}
public String getProFax() {
return proFax;
}
public void setProFax(String proFax) {
this.proFax = proFax;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
}
點擊Bill代碼
package pojo;
import java.math.BigDecimal;
import java.util.Date;
public class Bill {
private int id; //id
private String billCode; //賬單編碼
private String productName; //商品名稱
private String productDesc; //商品描述
private String productUnit; //商品單位
private BigDecimal productCount; //商品數量
private BigDecimal totalPrice; //總金額
private Integer isPayment; //是否支付
private Integer createdBy; //創建者
private Date creationDate; //創建時間
private Integer modifyBy; //更新者
private Date modifyDate; //更新時間
private Integer providerId; //供應商id
private String providerName;//供應商名字
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getBillCode() {
return billCode;
}
public void setBillCode(String billCode) {
this.billCode = billCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductDesc() {
return productDesc;
}
public void setProductDesc(String productDesc) {
this.productDesc = productDesc;
}
public String getProductUnit() {
return productUnit;
}
public void setProductUnit(String productUnit) {
this.productUnit = productUnit;
}
public BigDecimal getProductCount() {
return productCount;
}
public void setProductCount(BigDecimal productCount) {
this.productCount = productCount;
}
public BigDecimal getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}
public Integer getIsPayment() {
return isPayment;
}
public void setIsPayment(Integer isPayment) {
this.isPayment = isPayment;
}
public Integer getCreatedBy() {
return createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public Integer getModifyBy() {
return modifyBy;
}
public void setModifyBy(Integer modifyBy) {
this.modifyBy = modifyBy;
}
public Date getModifyDate() {
return modifyDate;
}
public void setModifyDate(Date modifyDate) {
this.modifyDate = modifyDate;
}
public Integer getProviderId() {
return providerId;
}
public void setProviderId(Integer providerId) {
this.providerId = providerId;
}
public String getProviderName() {
return providerName;
}
public void setProviderName(String providerName) {
this.providerName = providerName;
}
}
- 然後編寫數據庫連接用的文件
點擊文件後綴為.properties
driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/數據庫名字?useUnicode=true&characterEncoding=utf8
username=賬號
password=密碼
-
idea連接數據庫(不在此展示,自行解決)
-
編寫過濾器,使我們網頁每次都用utf-8編碼
點擊過濾器代碼
import javax.servlet.*;
import java.io.IOException;
public class Filter implements javax.servlet.Filter {
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
chain.doFilter(request,response);
}
public void destroy() {
}
}
- 編寫數據庫的公共類,實現增刪改查SRUD功能
package com.meteor.dao;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;
//操作數據庫的公共類
public class BaseDao {
private static final String driver;
private static final String url;
private static final String username;
private static final String password;
//靜態代碼塊,隨着類的加載而加載
static{
Properties properties = new Properties();//可以讓文件內容以鍵值對的形式讀取
//將文件內容讀出
InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
try {
//properties.load()從輸入位元組流讀取屬性列表(鍵和元素對)。
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}
driver = properties.getProperty("driver");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");
}
//獲取數據庫的連接
public static Connection getConnection() {
Connection connection = null;
try {
Class.forName(driver);//加載驅動
//嘗試建立與給定數據庫URL的連接。
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
//編寫查詢公共方法
public static ResultSet execute(Connection connection,String sql,Object[] params,ResultSet resultSet,PreparedStatement preparedStatement) throws SQLException {
//connection.prepareStatement(sql)創建一個 PreparedStatement對象,用於將參數化的SQL語句發送到數據庫。
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
preparedStatement.setObject(i+1,params[i]);//使用給定對象設置指定參數的值。
}
resultSet = preparedStatement.executeQuery();//返回查詢結果
return resultSet;
}
//編寫增刪改公共方法
public static int execute(Connection connection,String sql,Object[] params,PreparedStatement preparedStatement) throws SQLException {
//connection.prepareStatement(sql)創建一個 PreparedStatement對象,用於將參數化的SQL語句發送到數據庫。
preparedStatement = connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
preparedStatement.setObject(i+1,params[i]);
}
int updateRows = preparedStatement.executeUpdate();
return updateRows;
}
//釋放資源
public static boolean closeResource(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) {
boolean flag = true;
if(resultSet != null) {
try {
resultSet.close();
//GC回收機制,如果對象為null,就會被回收。
resultSet = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
if(preparedStatement != null) {
try {
preparedStatement.close();
//GC回收機制,如果對象為null,就會被回收。
preparedStatement = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
if(connection != null) {
try {
connection.close();
//GC回收機制,如果對象為null,就會被回收。
connection = null;
} catch (SQLException e) {
e.printStackTrace();
flag = false;
}
}
return flag;
}
}
- 編寫service服務層代碼,驗證登錄是否正確
import dao.BaseDao;
import dao.user.UserDao;
import dao.user.UserDaoImpl;
import pojo.User;
import java.sql.Connection;
public class UserServiceImpl implements UserService{
public User login(String userCode, String password) {
UserDaoImpl userDao = new UserDaoImpl();
Connection connection = BaseDao.getConnection();//連接數據庫
User user = userDao.getLoginUser(connection, userCode);//獲得登錄用戶信息
//對登錄的用戶賬號密碼進行判斷
if(user.getUserPassword() == null ? password == null : user.getUserPassword().equals(password)) {
BaseDao.closeResource(connection,null,null);
return user;
}else {
BaseDao.closeResource(connection,null,null);
System.out.println("密碼錯誤");
return null;
}
}
}
7.編寫servlet業務層代碼,和前端交互
package com.meteor.servlet.user;
import com.meteor.pojo.User;
import com.meteor.service.user.UserService;
import com.meteor.service.user.UserServiceImpl;
import com.meteor.util.Constants;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class LoginServlet extends HttpServlet {
//控制層調用業務層代碼
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("別出bug");
//獲取前端輸入的用戶名和密碼
String userCode = req.getParameter("userCode");
String userPassword = req.getParameter("userPassword");
//和數據庫的用戶密碼對比,調用業務層
UserServiceImpl userService = new UserServiceImpl();
User user = userService.login(userCode, userPassword);
if(user != null) { //查有此人
//將用戶信息放到session中
req.getSession().setAttribute(Constants.USER_SESSION,user);
//登錄成功,跳轉到內部主頁
resp.sendRedirect("jsp/frame.jsp");
}else {
//查無此人,轉回登錄頁面
req.setAttribute("error","用戶密碼不正確");
req.getRequestDispatcher("login.jsp").forward(req,resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
- 工具類用來存放session值
點擊查看代碼
public class Constants {
public static final String USER_SESSION = "userSession";
}
- 在web.xml設置servlet和filter過濾器
<!-- 字符編碼過濾器 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>com.meteor.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 設置歡迎頁面 -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.meteor.servlet.user.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login.do</url-pattern>
</servlet-mapping>
三、總結
- 前端代碼頁面都是cpoy的,若想獲取前端代碼可私信我。
- 對於smdms登錄內容就總結這麼多,也是跟着狂神學的,代碼也沒怎麼改進,只是想自己複習理解一遍。如果有不足之處,希望大家多多包涵,多多支持。如果有不懂的地方可以直接私信問我,歡迎來訪!
- 我將會繼續更新關於Java的學習知識,以及此項目的後續功能,感興趣的小夥伴可以關注一下。
- 文章寫得比較走心,用了很長時間,絕對不是copy過來的!
- 尊重每一位學習知識的人,同時也尊重每一位分享知識的人。