标签:删除 list app mat lis strong prim image sub
<a class="btn btn-sm btn-primary" th:href="@{/update/} + ${emp.id} ">修改</a>
controller实现页面的跳转
//修改 @GetMapping("/update/{id}") public String updataEmp(@PathVariable("id")Integer id, Model model){ Employee employee = employeeDao.get(id); model.addAttribute("emp",employee); //部门选择的修改 Collection<Department> departments = departmentDao.getDepartments(); model.addAttribute("depts",departments); return "emp/update"; }
<form th:action="@{/update1}" method="post"> <!--发送put请求修改员工数据--> <!-- 1、SpringMVC中配置HiddenHttpMethodFilter;(SpringBoot自动配置好的) 2、页面创建一个post表单 3、创建一个input项,name="_method";值就是我们指定的请求方式 --> <input type="hidden" name="_method" value="put" th:if="${emp!=null}"/> <!-- id --> <input type="hidden" name="id" th:if="${emp!=null}" th:value="${emp.id}"> <div class="form-group"> <label>LastName</label> <input name="lastName" type="text" class="form-control"
placeholder="zhangsan" th:value="${emp!=null}?${emp.lastName}"> </div> <div class="form-group"> <label>Email</label> <input name="email" type="email" class="form-control"
placeholder="zhangsan@atguigu.com" th:value="${emp!=null}?${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!=null}?${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!=null}?${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.id"> <option th:each="dept:${depts}" th:text="${dept.departmentName}" th:selected="${dept.id == emp.department.id}" th:value="${dept.id}">1</option> </select> </div> <div class="form-group"> <label>Birth</label> <input name="birth" type="text" class="form-control"
placeholder="zhangsan" th:value="${emp!=null}?${#dates.format(emp.birth, ‘yyyy-MM-dd HH:mm‘)}"> </div> <button type="submit" class="btn btn-primary" th:text="${emp!=null}?‘修改‘:‘添加‘">添加</button> </form>
实现页面修改的controller:
//员工修改 @PutMapping("/update1") public String updataToEmp(Employee employee){ System.out.println(employee); //修改的数据 employeeDao.save(employee); return "redirect:/emps"; }
list.html中
<form th:action="@{/delete/}+${emp.id}" method="post"> <input type="hidden" name="_method" value="delete"> <button class="btn btn-sm btn-danger">删除</button> </form>
controller实现:
//删除请求 @DeleteMapping("/delete/{id}") public String delete(@PathVariable("id") Integer id){ employeeDao.delete(id); return "redirect:/emps"; }
标签:删除 list app mat lis strong prim image sub
原文地址:https://www.cnblogs.com/Mrchengs/p/10356983.html