当前位置: 首页 > news >正文

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

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@AutowiredEmployeeDao employeeDao;@Autowired  // AutowireDepartmentDao 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 pageCollection<Employee> employees = employeeDao.getAll();model.addAttribute("emps",employees);return "emp/list";}@GetMapping("/emp") // Get request for redirectionpublic String toAddpage(Model model){// Retrieve information of all departmentsCollection<Department> departments = departmentDao.getDepartment();model.addAttribute("departments",departments);return "emp/add";}@PostMapping("/emp")public String addEmp(Employee employee){// Adding operation forwardSystem.out.println("save=>"+employee);employeeDao.save(employee); // Call the underlying business method to save employee informationreturn "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 departmentsCollection<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 logicif (!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 messagemodel.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!

相关文章:

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

2024.5.11 Saturday Continued from 【WEEK11】 【DAY5】Employee Management System Part 6【English Version】 Contents 10.8. Delete and 404 Handling10.8.1. Modify list.html10.8.2. Modify EmployeeController.java10.8.3. Restart10.8.4. 404 Page Handling10.8.4.1. …...

【52】Camunda8-Zeebe核心引擎-Clustering与流程生命周期

Clustering集群 Zeebe本质是作为一个brokers集群运行&#xff0c;形成一个点对点网络。在这个网络中&#xff0c;所有brokers的功能与服务都相同&#xff0c;没有单点故障。 Gossip协议 Zeebe实现了gossip协议&#xff0c;并借此知悉哪些broker当前是集群的一部分。 集群使用…...

从零开始的软件测试学习之旅(八)jmeter线程组参数化及函数学习

jmeter线程组参数化及函数学习 Jmeter基础基本使用流程组件与元件 线程组线程的执行方式Jmeter组件执行顺序 常见属性设置查看结果数的作用域举例 Jmeter参数化实现方式1.用户定义参数2.用户参数3.函数4.csv数据文件设置 每日复习 Jmeter基础 基本使用流程 启动项目案例 启动…...

图文并茂:解析Spring Boot Controller返回图片的三种方式

欢迎来到我的博客&#xff0c;代码的世界里&#xff0c;每一行都是一个故事 图文并茂&#xff1a;解析Spring Boot Controller返回图片的三种方式 前言使用Base64编码返回图片使用byte数组返回图片使用Resource对象返回图片图片格式转换与性能对比 前言 在互联网的世界里&…...

问题处理记录 | 表输出报错 Packet for query is too large (5,214,153 > 4,194,304).

这个错误是由于MySQL服务器接收到的查询数据包太大而引起的。具体来说&#xff0c;错误消息中提到的数据包大小为5,214,153字节&#xff0c;而MySQL服务器默认只接受最大为4,194,304字节的数据包。 要解决这个问题&#xff0c;你可以尝试通过修改MySQL服务器的配置来增大max_a…...

数据结构_栈和队列(Stack Queue)

✨✨所属专栏&#xff1a;数据结构✨✨ ✨✨作者主页&#xff1a;嶔某✨✨ 栈&#xff1a; 代码&#xff1a;function/数据结构_栈/stack.c 钦某/c-language-learning - 码云 - 开源中国 (gitee.com)https://gitee.com/wang-qin928/c-language-learning/blob/master/function/…...

基于docker 的elasticsearch冷热分离及生命周期管理

文章目录 冷热集群架构的应用场景冷热集群架构的优势冷热集群架构实战搭建集群 索引生命周期管理认识索引生命周期索引生命周期管理的历史演变索引生命周期管理的基础知识Rollover&#xff1a;滚动索引 冷热集群架构的应用场景 某客户的线上业务场景如下&#xff1a;系统每天增…...

pikachu靶场(xss通关教程)

&#xff08;注&#xff1a;若复制注入代码攻击无效&#xff0c;请手动输入注入语句&#xff0c;在英文输入法下&#xff09; 反射型xss(get型) 1.打开网站 发现有个框&#xff0c;然后我们在框中输入一个“1”进行测试&#xff0c; 可以看到提交的数据在url处有显示&#xf…...

实验0.0 Visual Studio 2022安装指南

Visual Studio 2022 是一个功能强大的开发工具&#xff0c;对于计算机专业的学生来说&#xff0c;它不仅可以帮助你完成学业项目&#xff0c;还能为你将来的职业生涯打下坚实的基础。通过学习和使用 Visual Studio&#xff0c;你将能够更高效地开发软件&#xff0c;并在编程领域…...

数据结构之----线性表

线性表分为 顺序存储结构 和 链式存储结构 线性表的顺序存储结构&#xff1a; 线性表的顺序存储结构&#xff0c;指的是用一段地址连续的存储单元依次存储线性表的数据元素。 1&#xff0c;顺序表的结构&#xff1a; #define MAXSIZE 20 typedef int El…...

thinkphp5.1 模型auto

在ThinkPHP5.1中&#xff0c;模型的自动完成功能可以通过在模型类中定义auto属性来实现。这个属性是一个数组&#xff0c;包含了需要自动填充的字段和对应的处理规则。 以下是一个简单的例子&#xff0c;展示了如何在ThinkPHP5.1的模型中使用自动完成功能&#xff1a; <?…...

企业微信创建应用(一)

登录到企业微信后台管理(https://work.weixin.qq.com/)进入自建应用(应用管理-应用-创建应用) 3.查看参数AgentId和 Secret 4.企业微信查看效果...

Cosmo Bunny Girl

可爱的宇宙兔女郎的3D模型。用额外的骨骼装配到Humanoid上,Apple混合了形状。完全模块化,包括不带衣服的身体。 技术细节 内置,包括URP和HDRP PDF。还包括关于如何启用URP和HDRP的说明。 LOD 0:面:40076,tris 76694,verts 44783 装配了Humanoid。添加到Humanoid中的其他…...

初始化linux数据盘(3TB)分区-格式化-挂载目录

场景说明&#xff1a;某云给我们服务器加载了一块3TB的硬盘扩容&#xff08;没有直接扩&#xff0c;原因是原来的盘做的是mbr&#xff08;什么年代了&#xff0c;谁干的&#xff09;的分区&#xff0c;最大识别2TB&#xff09; 确认磁盘 输入命令lsblk 查看数据盘信息 &#…...

NFS网络文件系统的应用

1.配置2台服务器要求如下&#xff1a; a&#xff09;服务器1&#xff1a; 主机名&#xff1a;user-server.timinglee.org ip地址&#xff1a; 172.25.254.100 [rootserver100 桌面]# hostnamectl hostname user-server.timinglee.org [rootserver100 桌面]# ifconfig eth0: fl…...

AttributeError: module ‘PIL.Image‘ has no attribute ‘ANTIALIAS‘

问题描述 修改图片大小的时候&#xff0c;代码报错&#xff1a;AttributeError: module PIL.Image has no attribute ANTIALIAS 解决方案 在pillow的10.0.0版本中&#xff0c;ANTIALIAS方法被删除了。 方法1&#xff1a;修改版本&#xff08;不推荐&#xff09; pip instal…...

进程的共享主存通信实验

进程的共享主存通信 【预备知识】 共享存储区为进程提供了直接通过主存进行通信的有效手段&#xff0c;不像消息缓冲机制那样需要系统提供缓冲&#xff0c;也不像pipe机制那样需要事先建立一个特殊文件&#xff0c;而是由通信双方直接访问某些共享虚拟储存空间。在Linux中&…...

深度缓冲技术在AI去衣中的神奇作用

引言&#xff1a; 随着人工智能技术的飞速发展&#xff0c;其在图形处理和视觉领域的应用日益增多。AI去衣技术便是其中一个颇具争议但又技术上引人入胜的话题。今天&#xff0c;我们将深入探讨一项关键技术——深度缓冲&#xff08;Depth Buffering&#xff09;&#xff0c;它…...

能效?性能?一个关于Windows下使用openssl speed进行速度测试的诡异问题

问题描述 最近的某个软件用到了openssl&#xff0c;所以就想着测试一下速度。我的电脑是惠普的&#xff0c;CPU是AMD Ryzen 7 PRO 6850HS&#xff0c;系统是Win11。我使用openssl自带的speed测试加密/解密的速度&#xff0c;命令大致如下&#xff1a; openssl speed -evp aes…...

block性能考虑和线程安全

性能考虑 频繁地创建和销毁大量的 block 可能会对性能造成影响&#xff0c;特别是当这些 block 被拷贝到堆上时。同时&#xff0c;block 捕获大量数据时也会增加内存使用。 在讨论性能考虑时&#xff0c;主要关注的是 block 的创建、拷贝到堆上以及捕获变量的成本。以下是针对…...

屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!

5月28日&#xff0c;中天合创屋面分布式光伏发电项目顺利并网发电&#xff0c;该项目位于内蒙古自治区鄂尔多斯市乌审旗&#xff0c;项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站&#xff0c;总装机容量为9.96MWp。 项目投运后&#xff0c;每年可节约标煤3670…...

【论文笔记】若干矿井粉尘检测算法概述

总的来说&#xff0c;传统机器学习、传统机器学习与深度学习的结合、LSTM等算法所需要的数据集来源于矿井传感器测量的粉尘浓度&#xff0c;通过建立回归模型来预测未来矿井的粉尘浓度。传统机器学习算法性能易受数据中极端值的影响。YOLO等计算机视觉算法所需要的数据集来源于…...

python爬虫:Newspaper3k 的详细使用(好用的新闻网站文章抓取和解析的Python库)

更多内容请见: 爬虫和逆向教程-专栏介绍和目录 文章目录 一、Newspaper3k 概述1.1 Newspaper3k 介绍1.2 主要功能1.3 典型应用场景1.4 安装二、基本用法2.2 提取单篇文章的内容2.2 处理多篇文档三、高级选项3.1 自定义配置3.2 分析文章情感四、实战案例4.1 构建新闻摘要聚合器…...

RNN避坑指南:从数学推导到LSTM/GRU工业级部署实战流程

本文较长&#xff0c;建议点赞收藏&#xff0c;以免遗失。更多AI大模型应用开发学习视频及资料&#xff0c;尽在聚客AI学院。 本文全面剖析RNN核心原理&#xff0c;深入讲解梯度消失/爆炸问题&#xff0c;并通过LSTM/GRU结构实现解决方案&#xff0c;提供时间序列预测和文本生成…...

Web 架构之 CDN 加速原理与落地实践

文章目录 一、思维导图二、正文内容&#xff08;一&#xff09;CDN 基础概念1. 定义2. 组成部分 &#xff08;二&#xff09;CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 &#xff08;三&#xff09;CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 &#xf…...

20个超级好用的 CSS 动画库

分享 20 个最佳 CSS 动画库。 它们中的大多数将生成纯 CSS 代码&#xff0c;而不需要任何外部库。 1.Animate.css 一个开箱即用型的跨浏览器动画库&#xff0c;可供你在项目中使用。 2.Magic Animations CSS3 一组简单的动画&#xff0c;可以包含在你的网页或应用项目中。 3.An…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)

考察一般的三次多项式&#xff0c;以r为参数&#xff1a; p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]&#xff1b; 此多项式的根为&#xff1a; 尽管看起来这个多项式是特殊的&#xff0c;其实一般的三次多项式都是可以通过线性变换化为这个形式…...

Spring AI Chat Memory 实战指南:Local 与 JDBC 存储集成

一个面向 Java 开发者的 Sring-Ai 示例工程项目&#xff0c;该项目是一个 Spring AI 快速入门的样例工程项目&#xff0c;旨在通过一些小的案例展示 Spring AI 框架的核心功能和使用方法。 项目采用模块化设计&#xff0c;每个模块都专注于特定的功能领域&#xff0c;便于学习和…...

深度剖析 DeepSeek 开源模型部署与应用:策略、权衡与未来走向

在人工智能技术呈指数级发展的当下&#xff0c;大模型已然成为推动各行业变革的核心驱动力。DeepSeek 开源模型以其卓越的性能和灵活的开源特性&#xff0c;吸引了众多企业与开发者的目光。如何高效且合理地部署与运用 DeepSeek 模型&#xff0c;成为释放其巨大潜力的关键所在&…...

Java中栈的多种实现类详解

Java中栈的多种实现类详解&#xff1a;Stack、LinkedList与ArrayDeque全方位对比 前言一、Stack类——Java最早的栈实现1.1 Stack类简介1.2 常用方法1.3 优缺点分析 二、LinkedList类——灵活的双端链表2.1 LinkedList类简介2.2 常用方法2.3 优缺点分析 三、ArrayDeque类——高…...