本来想好好整理最后结束的
奈何又接了个项目 一个挺大的项目 更能运用
所以时间不够 就简单整理 算烂了个尾吧
首先:
1.人工AI取代程序员 对我来说是不对的 确实是骗外行的
但其确实强大 带来的便利 但也只有程序员才能完美部署并运用它
2.有多少人像我一样不喜欢wordexcelppt 喜欢用html或者记事本或者纸张去写
3.之前写的javaweb图书管理项目和springboot人员管理项目对比 天差地别
4.关于模板美化 一千二百多行代码 瞬间美观
主要显示页面 可以看到我抽出了公共部分
这个掏钱买的好看模板 不过改得我也够呛
<!DOCTYPE html>
<!--[if lt IE 7 ]>
<html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]>
<html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]>
<html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <!--<![endif]-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title> | 吉芳芳 | </title>
<!-- Styles -->
<link type="text/css" rel="stylesheet" th:href="@{/asserts/css/base.css}"/>
<link type="text/css" rel="stylesheet" th:href="@{/asserts/css/animate.css}"/>
<link type="text/css" rel="stylesheet" th:href="@{/asserts/css/magnific-popup.css}"/>
<link type="text/css" rel="stylesheet" th:href="@{/asserts/css/owl-carousel.css}"/>
<link type="text/css" rel="stylesheet" th:href="@{/asserts/css/style.css}"/>
<!-- /Styles -->
</head>
<body>
<!-- Wrapper All -->
<div class="rewall_fn_wrapper_all" data-nav-skin="transdark">
<!-- Wrapper -->
<div class="rewall_fn_wrapper">
<!-- Color Scheme -->
<div th:replace="~{commons/bar::color}"></div>
<!-- /Color Scheme -->
<!-- Left Sidebar -->
<!-- You can set up minimum and maximum width for sidebar (in px). Minimum width is 350 -->
<div th:replace="~{commons/bar::left}"></div>
<!-- /Left Sidebar -->
<!-- Main Content -->
<div class="rewall_fn_content">
<div class="fn__page">
<!-- About Section -->
<div th:replace="~{commons/bar::about}"></div>
<!-- /About Section -->
<section class="customer" id="employee">
<h3>
<a th:href="@{/emps}">员工管理</a>
</h3>
<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 class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
<th>id</th>
<th>lastName</th>
<th>email</th>
<th>gender</th>
<th>department</th>
<th>birth</th>
<!--我们还可以在显示的时候带一些操作按钮-->
<th>操作</th>
</tr>
</thead>
<tbody>
<tr th:each="emp:${emps}">
<td th:text="${emp.id}"></td>
<td>[[${emp.lastName}]]</td>
<td th:text="${emp.email}"></td>
<td th:text="${emp.gender==0?'女':'男'}"></td>
<td th:text="${emp.EDepartment.departmentName}"></td>
<!--<td th:text="${emp.birth}"></td>-->
<!--使用时间格式化工具-->
<td th:text="${#dates.format(emp.birth,'yyyy-MM-dd HH:mm')}"></td>
<!--操作-->
<td>
<a th:href="@{/emp/}+${emp.id}">编辑</a>
<a th:href="@{/delEmp/}+${emp.id}">删除</a>
</td>
</tr>
</tbody>
</table>
<!--添加员工按钮-->
<h4>
<a th:href="@{/emp}">添加员工</a>
</h4>
</div>
</main>
</div>
</div>
</section>
<!-- Customer Section -->
<div th:replace="~{commons/bar::customer}"></div>
<!-- /Customer Section -->
<!-- Contact Section -->
<div th:replace="~{commons/bar::contact}"></div>
<!-- /Contact Section -->
</div>
</div>
<!-- Main Content -->
</div>
<!-- /Wrapper -->
</div>
<!-- /Wrapper All -->
<!-- Scripts -->
<script type="text/javascript" th:src="@{/asserts/js/jquery.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/wow.min.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/magnific-popup.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/onepage.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/owl-carousel.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/isotope.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/parallax.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/waypoints.js}"></script>
<script type="text/javascript" th:src="@{/asserts/js/init.js}"></script>
</body>
</html>
点击增加和更新就会跳转到add 和 upgrade页面
只展示重要部分
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<form th:action="@{/emp}" method="post">
<div class="form-group">
<label>LastName</label>
<input type="text" class="form-control" name="lastName" placeholder="名字">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" name="email" placeholder="邮箱">
</div>
<div class="form-group">
<label>Gender</label><br/>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" value="1">
<label class="form-check-label">男</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" value="0">
<label class="form-check-label">女</label>
</div>
</div>
<div class="form-group">
<label>department</label>
<!--提交的是部门的ID-->
<select class="form-control" name="department">
<option th:each="dept:${departments}" th:text="${dept.departmentName}" th:value="${dept.id}">1</option>
</select>
</div>
<div class="form-group">
<label>Birth</label>
<input type="text" class="form-control" name="birth" placeholder="生日">
</div>
<button type="submit" class="btn btn-primary">添加</button>
</form>
</main>
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<form th:action="@{/updateEmp}" method="post">
<input name="id" type="hidden" class="form-control" th:value="${emp.id}">
<div class="form-group">
<label>LastName</label>
<input name="lastName" type="text" class="form-control" th:value="${emp.lastName}">
</div>
<div class="form-group">
<label>Email</label>
<input name="email" type="email" class="form-control" th:value="${emp.email}">
</div>
<div class="form-group">
<label>Gender</label><br/>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" value="1"
th:checked="${emp.gender==1}">
<label class="form-check-label">男</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="gender" value="0"
th:checked="${emp.gender==0}">
<label class="form-check-label">女</label>
</div>
</div>
<div class="form-group">
<label>department</label>
<!--提交的是部门的ID-->
<select class="form-control" name="department">
<option th:selected="${dept.id == emp.department}" th:each="dept:${departments}"
th:text="${dept.departmentName}" th:value="${dept.id}">1
</option>
</select>
</div>
<div class="form-group">
<label>Birth</label>
<input name="birth" type="text" class="form-control" th:value="${#dates.format(emp.birth,'yyyy-MM-dd HH:mm')}">
</div>
<button type="submit" class="btn btn-primary">修改</button>
</form>
</main>
重要的controller层:
注意post get 方法
package com.fang.controller;
import com.fang.mapper.DepartmentMapper;
import com.fang.mapper.EmployeeMapper;
import com.fang.pojo.Department;
import com.fang.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 java.util.List;
@Controller
public class EmployeeController {
@Autowired
EmployeeMapper employeeMapper;
@Autowired
DepartmentMapper departmentMapper;
//查询所有员工,返回列表页面
@GetMapping("/emps")
public String list(Model model){
List<Employee> employees = employeeMapper.getEmployees();
//将结果放在请求中
model.addAttribute("emps",employees);
return "dashboard";
}
//to员工添加页面
@GetMapping("/emp")
public String toAddPage(Model model){
//查出所有的部门,提供选择
List<Department> departments = departmentMapper.getDepartments();
model.addAttribute("departments",departments);
return "emp/add";
}
//员工添加功能
//接收前端传递的参数,自动封装成为对象[要求前端传递的参数名,和属性名一致]
@PostMapping("/emp")
public String addEmp(Employee employee){
System.out.println(employee);
employeeMapper.save(employee); //保存员工信息
//回到员工列表页面,可以使用redirect或者forward
return "redirect:/emps";
}
//to员工修改页面
@GetMapping("/emp/{id}")
public String toUpdateEmp(@PathVariable("id") Integer id,Model model){
//根据id查出来员工
Employee employee = employeeMapper.get(id);
System.out.println(employee);
//将员工信息返回页面
model.addAttribute("emp",employee);
//查出所有的部门,提供修改选择
List<Department> departments = departmentMapper.getDepartments();
model.addAttribute("departments",departments);
return "emp/update";
}
@PostMapping("/updateEmp")
public String updateEmp(Employee employee){
employeeMapper.update(employee);
//回到员工列表页面
return "redirect:/emps";
}
@GetMapping("/delEmp/{id}")
public String delEmp(@PathVariable("id") Integer id){
employeeMapper.delete(id);
return "redirect:/emps";
}
}
哈哈真的懒得再整理了
效果如我的上篇
接下来要好好搞搞一个springboot和vue项目了 下次再更
烂尾拜拜