springboot(36课时)考试内容及参考
一、样卷:
- 功能要求
请编写一个程序,完成对员工的管理 ,实现两个功能:
1、显示所有的员工。 2、添加员工。
- 具体功能要求及推荐实现步骤
接收老师发的springboot工程,把文件夹名改为ems-班级-学号(如:ems-ruanjian222-01),采用mvc架构,前端使用HTML+CSS+thymeleaf技术,后端采用springboot+springmvc+JPA技术开发此系统,实现步骤如下:
1、修改pom文件的artifactId为ems-班级-学号和name为ems-班级-学号。(5分)
2、创建实体类Employee、Department,根据业务提供需要的构造方法和setter/getter方法。(20分)
3、创建EmployeeRepository接口,继承JpaRepository(10分)
4、创建DepartmentRepository接口,继承JpaRepository(10分)
5、创建EmployeeController类,实现员工列表查询功能。(15分)
6、在EmployeeController实现跳转到添加页面。(5分)
7、在EmployeeController实现员工添加。(15分)
8、在employee_list.html实现展示所有员工。(10分)
9、在employee_add.html实现获取用户的输入发送给后端,如果添加成功,跳转到列表界面。(10分)
二、实现步骤
2.1.解压基础项目并修改文件夹名称
解压后修改项目所在的文件夹为 ems-班级-学号(如:ems-ruanjian222-01)
2.2.修改pom.xml文件中的项目信息
ems-班级-学号 1.0-SNAPSHOT ems-班级-学号
2.3.创建实体类Employee、Department
根据业务提供需要的构造方法和setter/getter方法。
(图片来源网络,侵删)@Entity(name = "department") public class Department { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name;//部门名称 public Department(){} public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
@Entity(name = "employee") public class Employee { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String name;//员工姓名 private String phone;//员工手机号码 @Column(name = "department_id") private Integer departmentId;//员工所属部门Id //private String departmentName;//员工所属部门名称 public Employee() { } public Integer getId() { return id; } public void setId(Integer 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 Integer getDepartmentId() { return departmentId; } public void setDepartmentId(Integer departmentId) { this.departmentId = departmentId; } }
2.4.创建EmployeeRepository接口
public interface EmployeeRepository extends JpaRepository { }
2.5.创建DepartmentRepository
public interface DepartmentRepository extends JpaRepository { }
2.6.开发EmployeeController
@Controller public class EmployeeController { @Autowired private EmployeeRepository employeeRepository; @Autowired private DepartmentRepository departmentRepository; @PostMapping("/saveEmployee") public String saveEmployee(Employee employee) { employeeRepository.save(employee); return "redirect:/getAllEmployees"; } @GetMapping("/getAllEmployees") public String getAllEmployees(HttpServletRequest request) { request.setAttribute("employees", employeeRepository.findAll()); return "employee_list"; } @GetMapping("/employee_add") public String showAddEmployeeForm(HttpServletRequest request) { request.setAttribute("departments", departmentRepository.findAll()); return "employee_add"; } }
2.7.开发员工列表页面employee_list.html
员工列表
员工列表
ID 姓名 电话 部门ID ID 姓名 电话 部门ID 2.8.员工添加页面(employee_add.html)
添加员工
添加员工
姓名:
电话:
所属部门: 部门名称sql:
CREATE DATABASE /*!32312 IF NOT EXISTS*/`ems` /*!40100 DEFAULT CHARACTER SET utf8mb4 */; USE `ems`; /*Table structure for table `department` */ DROP TABLE IF EXISTS `department`; CREATE TABLE `department` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; /*Data for the table `department` */ insert into `department`(`id`,`name`) values (1,'人力资源部'),(2,'销售部'),(3,'生产部'); /*Table structure for table `employee` */ DROP TABLE IF EXISTS `employee`; CREATE TABLE `employee` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `phone` varchar(30) NOT NULL, `department_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; /*Data for the table `employee` */ insert into `employee`(`id`,`name`,`phone`,`department_id`) values (1,'唐僧','135112345678',1),(2,'孙悟空','13645678932',2),(3,'猪八戒','13812345678',3);
练习
请编写一个程序,完成对商品的管理 ,实现显示所有商品、添加商品功能。
数据库名称:gms
(图片来源网络,侵删)表名
goods 商品表 列名
(图片来源网络,侵删)数据类型(精度范围)
空/非空
约束条件
注释
id
int
非空
PK
商品id
name
varchar(50)
非空
商品名字 price
float
非空
商品价格
category_id
int
非空
商品所属类别id
表名
category 商品类别表 列名
数据类型(精度范围)
空/非空
约束条件
注释
id int
非空
PK
商品类别id
name
varchar(30)
非空
商品类别名称
CREATE DATABASE /*!32312 IF NOT EXISTS*/`gms` /*!40100 DEFAULT CHARACTER SET utf8mb4 */; USE `gms`; /*Table structure for table `department` */ DROP TABLE IF EXISTS `category`; CREATE TABLE `category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; /*Data for the table `department` */ insert into `category`(`id`,`name`) values (1,'图书'),(2,'服装'),(3,'玩具'); /*Table structure for table `employee` */ DROP TABLE IF EXISTS `good`; CREATE TABLE `good` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30) NOT NULL, `maker` varchar(30) NOT NULL, `category_id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4; /*Data for the table `employee` */ insert into `good`(`id`,`name`,`maker`,`category_id`) values (1,'十万个为什么','华夏书局',1),(2,'短袖','李宁',2),(3,'汪汪队玩家','spride',3);
- 具体功能要求及推荐实现步骤