【WEEK11】 【DAY6】Employee Management System Part 7【English Version】

news2024/10/5 18:33:52

2024.5.11 Saturday
Continued from 【WEEK11】 【DAY5】Employee Management System Part 6【English Version】

Contents

  • 10.8. Delete and 404 Handling
    • 10.8.1. Modify list.html
    • 10.8.2. Modify EmployeeController.java
    • 10.8.3. Restart
    • 10.8.4. 404 Page Handling
      • 10.8.4.1. Move the 404.html file into it
      • 10.8.4.2. Restart and Run
    • 10.8.5. Logout
      • 10.8.5.1. Modify commons.html
      • 10.8.5.2. Modify LoginController.java
      • 10.8.5.3. Restart
  • 10.9. Summary
    • 10.9.1. How to Build a Website
    • 10.9.2. Templates

10.8. Delete and 404 Handling

10.8.1. Modify list.html

Insert image description here

<a class="btn btn-sm btn-danger" th:href="@{/delemp/{id}(id=${emp.getId})}">Delete</a><!--@{/delemp/}+${emp.getId()} can also be written this way-->

10.8.2. Modify EmployeeController.java

package com.P14.controller;

import com.P14.dao.DepartmentDao;
import com.P14.dao.EmployeeDao;
import com.P14.pojo.Department;
import com.P14.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Collection;

@Controller
public class EmployeeController {
    // Query all employees
    @Autowired
    EmployeeDao employeeDao;
    @Autowired  // Autowire
    DepartmentDao departmentDao;

    @RequestMapping("/emps")    // Whenever dashboard.html requests th:href="@{emps}" (line 89), it will be redirected to @RequestMapping("/emps")
    public String list(Model model){    // Then it will query all employees, and modify: how to display them on the front-end page
        Collection<Employee> employees = employeeDao.getAll();
        model.addAttribute("emps",employees);
        return "emp/list";
    }

    @GetMapping("/emp") // Get request for redirection
    public String toAddpage(Model model){
        // Retrieve information of all departments
        Collection<Department> departments = departmentDao.getDepartment();
        model.addAttribute("departments",departments);
        return "emp/add";
    }

    @PostMapping("/emp")
    public String addEmp(Employee employee){
        // Adding operation forward
        System.out.println("save=>"+employee);
        employeeDao.save(employee); // Call the underlying business method to save employee information
        return "redirect:/emps";    // After clicking "Add" on the "Add Employee" page, redirect to the "Employee Management" page
    }


    // Go to the employee update page -> should be able to retrieve the original data
    @GetMapping("/emp/{id}")
    public String toUpdateEmp(@PathVariable("id") Integer id,Model model){
        Employee employee = employeeDao.getEmployeeById(id);
        model.addAttribute("emp",employee);

        // Retrieve information of all departments
        Collection<Department> departments = departmentDao.getDepartment();
        model.addAttribute("departments",departments);

        return "emp/update";
    }

    @PostMapping("/updateEmp")
    public String updateEmp(Employee employee){
        employeeDao.save(employee);
        return "redirect:/emps";
    }

    // Delete employee
    @GetMapping("/delemp/{id}")
    public String deleteEmp(@PathVariable("id") int id){
        employeeDao.delete(id);
        return "redirect:/emps";
    }

}

10.8.3. Restart

Insert image description here
Insert image description here

10.8.4. 404 Page Handling

Create error folder

10.8.4.1. Move the 404.html file into it

Insert image description here
To prevent loss of page style, add two slashes //
Insert image description here

10.8.4.2. Restart and Run

Enter any URL that does not correspond to a page
Insert image description here

If the 404.html is not placed in the error folder, the error page will be displayed with the default browser style:
Insert image description here

10.8.5. Logout

10.8.5.1. Modify commons.html

Insert image description here

<a class="nav-link" th:href="@{/user/logout}">Sign out</a>

10.8.5.2. Modify LoginController.java

package com.P14.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {

    @RequestMapping("/user/login")
    public String login(@RequestParam("username") String username,
                       @RequestParam("password") String password,
                       Model model,
                       HttpSession session){
        // Business logic
        if (!StringUtils.isEmpty(username) && "123456".equals(password)){
            session.setAttribute("loginUser",username);
            // Login successful, redirect to /main (already set to redirect to dashboard.html in MyMvcConfig)
            return "redirect:/main.html";
        }else {
            // Failed login message
            model.addAttribute("msg","Invalid username or password");
            return "index";
        }
    }

    // Logout
    @RequestMapping("/user/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "redirect:/index.html";
    }
}

10.8.5.3. Restart

Insert image description here

  • After login, not logging out -> even if returned to the login page -> can directly access desired URL by entering it again
    Insert image description here
    Return to the login page:
    Insert image description here
    At this point, desired URLs can be accessed directly by entering them:
    For example: http://localhost:8080/emps
    Insert image description here

For example: http://localhost:8080/main.html
Insert image description here

  • After login, then logout -> back to the login page -> must login again to access desired URL
    Insert image description here
    Return to the login page:
    Insert image description here
    Attempting to access main.html by modifying the URL fails, indicating successful user logout.
    Insert image description here

10.9. Summary

10.9.1. How to Build a Website

10.9.1.1. Frontend: Design the appearance using layui
10.9.1.2. Database design (Database design challenges)
10.9.1.3. Make the frontend self-executing and independent
10.9.1.4. How to connect data interfaces: JSON, objects, all in one!
10.9.1.5. Frontend-backend integration testing

10.9.2. Templates

10.9.3. Have a set of familiar backend templates: Essential for work! Recommended to use: x-admin
10.9.4. Frontend pages: At least be able to combine a website page using frontend frameworks

  • index
  • about
  • blog
  • post
  • user

10.9.5. Make this website able to run independently!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1669427.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

如何取消格式化SD卡并恢复丢失的数据?

在相机中格式化SD卡后&#xff0c;您将丢失卡上的所有文件。如果有恢复形成操作的选项&#xff0c;您可以轻松取回文件。然而&#xff0c;相机或任何其他设备中没有这样的选项。它无法直接取消格式化相机SD卡&#xff0c;但您仍然可以从格式化的SD卡中恢复文件。 为什么格式化后…

excel常见图表大全

Excel图表是一种以图形形式呈现数据的工具&#xff0c;它将数字和统计信息转化为直观的视觉元素&#xff0c;如线图、柱状图、饼图等。这些图表可以帮助人们更容易地理解数据的趋势、关系和模式。 使用场景 Excel图表广泛应用于各个领域&#xff0c;包括&#xff1a; 商务分…

服装定制|基于SSM+vue的服装定制系统的设计与实现(源码+数据库+文档)

服装定制系统 目录 基于SSM&#xff0b;vue的服装定制系统的设计与实现 一、前言 二、系统设计 三、系统功能设计 1系统功能模块 2管理员功能模块 3用户后台管理模块 四、数据库设计 五、核心代码 六、论文参考 七、最新计算机毕设选题推荐 八、源码获取&#xf…

基于Springboot的村庄果园预售系统(有报告)。Javaee项目,springboot项目。

演示视频&#xff1a; 基于Springboot的村庄果园预售系统&#xff08;有报告&#xff09;。Javaee项目&#xff0c;springboot项目。 项目介绍&#xff1a; 采用M&#xff08;model&#xff09;V&#xff08;view&#xff09;C&#xff08;controller&#xff09;三层体系结构…

2024情感聊天赛道,al工具制做,视频一分钟一条,日入500+

在这个领域&#xff0c;我们可以利用AI技术快速制作情感文章和闲聊内容。基本原理是结合热门创意文案&#xff0c;通过AI生成情感聊天短视频&#xff0c;然后在各大网站进行独家代理&#xff0c;这个领域的竞争相对较小&#xff0c;可以说是一片蓝海。 项 目 地 址 &#xff…

【目标检测论文解读复现NO.38】基于改进YOLOv8模型的轻量化板栗果实识别方法

前言 此前出了目标改进算法专栏&#xff0c;但是对于应用于什么场景&#xff0c;需要什么改进方法对应与自己的应用场景有效果&#xff0c;并且多少改进点能发什么水平的文章&#xff0c;为解决大家的困惑&#xff0c;此系列文章旨在给大家解读最新目标检测算法论文&#xff0c…

【机器学习】LoFTR:革命性图像特征批评技术等领跑者

LoFTR&#xff1a;革命性图像特征匹配技术的领跑者 一、引言二、LoFTR技术的创新之处三、LoFTR技术的实现原理四、LoFTR技术的代码实例五、结语 一、引言 在3D计算机视觉领域&#xff0c;图像特征匹配技术一直是研究的热点和难点。随着技术的不断发展&#xff0c;传统的特征检…

电子学会C/C++编程等级考试2024年03月(八级)真题解析

C/C编程&#xff08;1~8级&#xff09;全部真题・点这里 第1题&#xff1a;道路 N个以 1 … N 标号的城市通过单向的道路相连:。每条道路包含两个参数&#xff1a;道路的长度和需要为该路付的通行费&#xff08;以金币的数目来表示&#xff09; Bob and Alice 过去住在城市 1.在…

ACE框架学习4

目录 ACE Proactor框架 异步I/O工厂类 ACE_Handler类 前摄式Acceptor-Connector类 ACE_Proactor类 ACE Streams框架 ACE_Model类 ACE_Streams类 ACE Proactor框架 ACE Proactor框架实现了proactor模式&#xff0c;也就是异步网络模式&#xff0c;允许事件驱动…

并行执行线程资源管理方式——《OceanBase 并行执行》系列 3

在某些特定场景下&#xff0c;由于需要等待线程资源&#xff0c;并行查询会遇到排队等待的情况。本篇博客将介绍如何管理并行执行线程资源&#xff0c;以解决这种问题。 《OceanBase并行执行》系列的内容分为七篇博客&#xff0c;本篇是其中的第三篇。前2篇如下&#xff1a; 一…

容器组件:Column ,Row(HarmonyOS学习第四课【4.1】)

容器组件-Column Column 容器组件是沿垂直方向布局的容器。该组件从APIVersion7开始支持从API version 9开始&#xff0c;该接口支持在ArkTs,卡片中使用。其可以包含子组件 Column(value?: {space?: string | number}) 参数 space 参数类型string | number 是否必填&am…

锁策略详解:互斥锁、读写锁、乐观锁与悲观锁、轻量级锁与重量级锁、自旋锁、偏向锁、可重入锁与不可重入锁、公平锁与非公平锁

一.锁策略 锁策略指的是在多线程编程中用于管理共享资源访问的规则和技术。它们确保在任何给定时间只有一个线程可以访问共享资源&#xff0c;以防止竞态条件和数据不一致性问题。常见的锁策略包括&#xff1a; 互斥锁&#xff08;Mutex&#xff09;&#xff1a;最常见的锁类型…

WPS表格:对比少于1万的两列数据

当我们需要对于A、B两列乱序的数据&#xff0c;找出A列中某一项B列有没有&#xff0c;或者找出B列中的某一项A列有没有&#xff0c;都可以先将这两列数据放入WPS表格中&#xff1a; 1.选中C列的第一行的单元格&#xff0c;在函数区输入函数 如果我们以A为基准&#xff0c;找A中…

项目分享|基于ELF 1S开发板完成的物联网开源项目

ElfBoard作为飞凌嵌入式旗下教育品牌&#xff0c;自成立以来&#xff0c;持续吸引着各界的瞩目&#xff0c;其中也赢得了一些工程师的青睐。今天&#xff0c;就和各位小伙伴分享一位杰出工程师借助ELF 1S开发板完成的嵌入式物联网项目&#xff0c;见证智慧与技术的火花。 关于…

二、计算机基础(Java零基础二)

&#x1f33b;&#x1f33b;目录 一、认识计算机二、计算机的组成2.1 计算机硬件&#xff08;摸得着&#xff0c;看得见&#xff09;2.1.1 计算机硬件组成2.1.2 冯.诺依曼(计算机之父)体系结构 2.2 计算机软件&#xff08;摸不着&#xff0c;看不见&#xff09; 三、电脑常用快…

LVDS 源同步接口

传统数据传输通常采用系统同步传输方式&#xff0c;多个器件基于同一时钟源进行系统同步&#xff0c;器件之间的数据传输时序关系以系统时钟为参考&#xff0c;如图1所示。系统同步传输方式使各器件处于同步工作模式&#xff0c;但器件之间传输数据的传输时延难以确定&#xff…

Remix 集成 MUI

Remix 如何接入 MUI 组件库&#xff0c;MUI 官网提供了一个 Remix 接入 MUI 的例子&#xff0c;用的是老的 Remix版本&#xff0c;如何接入新的 Vite 版本呢&#xff1f; 由于 MUI 支持 SSR&#xff0c;只需要改造对应的 Client 和 Server 即可实现。安装 MUI 组件组件库&…

实现字符串复制(C语言)

一、N-S流程图&#xff1b; 二、运行结果&#xff1b; 三、源代码&#xff1b; # define _CRT_SECURE_NO_WARNINGS # include <stdio.h>int main() {//初始化变量值&#xff1b;int i 0;char a[100], b[100];//获取字符串&#xff1b;printf("请为数组a输入字符串…

如何在外网访问内网共享文件?

在日常工作和生活中&#xff0c;我们经常会遇到外网访问内网共享文件的需求。我们可能需要远程访问公司内部的共享文件夹&#xff0c;或者与不同地区的合作伙伴共享文件。由于网络安全的限制&#xff0c;外网访问内网的共享文件并不是一件容易的事情。 为了解决这个问题&#x…

java项目之车辆管理系统(springboot+vue+mysql)

风定落花生&#xff0c;歌声逐流水&#xff0c;大家好我是风歌&#xff0c;混迹在java圈的辛苦码农。今天要和大家聊的是一款基于springboot的车辆管理系统。项目源码以及部署相关请联系风歌&#xff0c;文末附上联系信息 。 项目简介&#xff1a; 车辆管理系统的主要使用者分…