6)、CRUD-员工添加
@Controller
public class EmployeeCtrl {
@Autowired
EmployeeDao dao;
@Autowired
DepartmentDao departmentDao;
//列出所有员工
@GetMapping("/emps")
public String list(Model model){
Collection<Employee> collection = dao.getAll();
model.addAttribute("emps",collection);
return "employee/list";
}
//添加页面
@GetMapping("/emp")
public String addVide(Model model){
//查询部门信息
Collection<Department> collection = departmentDao.getDepartments();
model.addAttribute("deparms",collection);
return "employee/add";
}
}
添加页面
<body>
<div th:replace="commons/bar::nav"></div>
<div class="container-fluid" >
<div class="row">
<div th:replace="commons/bar::#sidebar(activeUri='employee')"></div>
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
<div class="table-responsive">
<form>
<div class="form-group">
<label>LastName</label>
<input type="text" class="form-control" placeholder="zhangsan">
</div>
<div class="form-group">
<label>Email</label>
<input type="email" class="form-control" placeholder="zhangsan@atguigu.com">
</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>
<select class="form-control">
<option th:each="dep:${deparms}" th:value="${dep.id}" th:text="${dep.departmentName}">1</option>
</select>
</div>
<div class="form-group">
<label>Birth</label>
<input type="text" class="form-control" placeholder="zhangsan">
</div>
<button type="submit" class="btn btn-primary">添加</button>
</form>
</div>
</main>
</div>
</div>
</body>