目录
3.2.1将 Bootstrap 相关的 css,js 两个文件夹复制到 web 目录下
3.3.1在 src 中创建 com.work.user 包,在其中创建以下类
1. 需求分析
-
完成一个用户信息管理系统(基于 BS 架构),功能如下:
- 展示用户信息
- 添加用户信息
- 删除用户信息(可以删除选中用户)
- 修改用户信息(包括用户数据的回显)
-
效果图如下:
用户信息列表:
添加用户信息:
删除用户信息:
修改用户信息:
2. 概要设计
2.1 技术选型
- Tomcat 服务器
- Servlet
- JSP
- Bootstrap
- Map集合对象
2.2 项目结构设计(为下文的模块结构)
2.3 User类(JavaBean)设计
package com.work.user;
public class User {
private int id;
private String grade;
private String xh;
private String name;
private String department;
public User(){
}
public User(int id, String grade, String xh, String name, String department) {
this.id = id;
this.grade = grade;
this.xh = xh;
this.name = name;
this.department = department;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getXh() {
return xh;
}
public void setXh(String xh) {
this.xh = xh;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", grade='" + grade + '\'' +
", xh='" + xh + '\'' +
", name='" + name + '\'' +
", department='" + department + '\'' +
'}';
}
}
2.4 UserDao(单例模式)设计
package com.work.user;
import java.util.HashMap;
import java.util.Map;
public class UserDao {
private static UserDao userDao;
private UserDao(){}
public static synchronized UserDao getInstance(){
if(userDao == null){
userDao = new UserDao();
}
return userDao;
}
public static Map<Integer, User> map = new HashMap<>();
static {
map.put(1, new User(1,"计BG192","6454111113","康玉学","曙光大数据学院"));
map.put(2, new User(2,"管理BG202","6412129228","韩梅梅","人文艺术学院"));
map.put(3, new User(3,"自BG192","5111239232","李蕾","电信学院"));
map.put(4, new User(4,"会计BG182","9411118215","秦毅","人文艺术学院"));
map.put(5, new User(5,"大数据BG171","6511239232","杨树林","曙光大数据学院"));
map.put(6, new User(6,"自BG192","6411117356","张三","电信学院"));
}
public static Map<Integer, User> getALlUser() {
return map;
}
public static void deleteUser(int id){
map.remove(id);
}
public static void addUser(String grade, String xh, String name, String department){
int indexMax = map.keySet().stream().max((o1,o2) ->o1-o2).get();
int i = indexMax+1;
map.put(i,new User(i, grade, xh, name, department));
}
public static void updateUser(User user){
Integer id = user.getId();
map.put(id, user);
}
}