springboot(36课时)考试内容及参考

06-01 1269阅读

 一、样卷: 

  • 功能要求

    请编写一个程序,完成对员工的管理 ,实现两个功能:

    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方法。

      springboot(36课时)考试内容及参考
      (图片来源网络,侵删)
      @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 

      springboot(36课时)考试内容及参考
      (图片来源网络,侵删)

      表名

      goods 商品表

      列名

      springboot(36课时)考试内容及参考
      (图片来源网络,侵删)

      数据类型(精度范围)

      空/非空

      约束条件

      注释

      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);

       

免责声明:我们致力于保护作者版权,注重分享,被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理! 图片声明:本站部分配图来自人工智能系统AI生成,觅知网授权图片,PxHere摄影无版权图库和百度,360,搜狗等多加搜索引擎自动关键词搜索配图,如有侵权的图片,请第一时间联系我们。

目录[+]

取消
微信二维码
微信二维码
支付宝二维码