构建员工添加请求
com\springboot\controller\EmployeeController.java
/*调转到员工添加页 携带部门信息 restful风格*/
@GetMapping("/emp")
public String toAddPage(Model model){
//获取所有的部门
Collection departments = departmentDao.getDepartments();
model.addAttribute("departments",departments);
return "add";
}
/*添加员工 restful风格*/
@PostMapping("/emp")
public String addEmp(Employee emp){
employeeDao.save(emp);
//重定向到员工列表请求
return "redirect:/employee";
}
在list.html增加添加员工按钮
resources\templates\list.html
构建添加页面
resources\templates\add.html
form表单:
姓名
邮箱
性别
男
女
部门
th:value="${dept.getId()}"
th:text="${dept.getDepartmentName()}">
生日
添加
日期格式设置
springboot默认的时间格式为 yyyy/MM/dd 如果要用其他格式就需要在配置文件中配置:
spring:
mvc:
date-format: yyyy-MM-dd
测试访问:
添加:
列表显示:
原文:https://www.cnblogs.com/applesnt/p/12686587.html