Springboot简易实战-添加和修改员工功能实现
一、添加员工实现
1.前端首页设置添加员工按钮:接收后端请求
<h2><a class="btn btn-sm btn-success" th:href="@{/emp/addEmp}">添加员工</a></h2>
2.后端跳转请求
@Autowired
private DepartmentDao departmentDao;
@GetMapping("emps/add")
public String toAddPage(Model model){
Collection<Department> departments = departmentDao.getDepartments();
model.addAttribute("departments",departments);
return "emps/addEmp";
}
3.创建添加员工的前端页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Dashboard Template for Bootstrap</title>
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link href="/css/dashboard.css" rel="stylesheet">
<style type="text/css">
@-webkit-keyframes chartjs-render-animation {
from {
opacity: 0.99
}
to {
opacity: 1
}
}
@keyframes chartjs-render-animation {
from {
opacity: 0.99
}
to {
opacity: 1
}
}
.chartjs-render-monitor {
-webkit-animation: chartjs-render-animation 0.001s;
animation: chartjs-render-animation 0.001s;
}
</style>
</head>
<body>
<div th:replace="~{commons/commons::topbar}"></div>
<div class="container-fluid">
<div class="row">
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div th:replace="~{commons/commons::sidebar}"></div>
<form action="">
<div class="form-group">
<label>LastName</label>
<input type="text" name="lastName" class="form-control" placeholder="大力">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" name="email" class="form-control" placeholder="1231241244@qq.com">
</div>