对于修改连接的uri
在list.html中
<a class="btn btn-sm btn-primary" th:href="@{/update/} + ${emp.id} ">修改</a>
修改需要知道id,所以路径上需要有有该修改的员工id
两个属性是要进行拼串的不可以写在一起

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";
}
在add.html文件夹中复制并且命名为update.html
 
注意使用的RESTFUL方式,使用put请求时的隐藏域以及id的隐藏域
对数据进行的回显判断操作
<form th:action="@{/update1}" method="post">
<!--发送put请求修改员工数据-->
<!--
、SpringMVC中配置HiddenHttpMethodFilter;(SpringBoot自动配置好的)
、页面创建一个post表单
、创建一个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="" 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="" 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}"
></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";
}

最新文章

  1. Unity3D &quot;Library\UnityAssemblies\UnityEngine.xml&quot; is denied错误解决方法
  2. 02-C#入门(枚举、结构等)
  3. 使用oh-my-zsh后导致的卡顿问题
  4. Unity3D核心类型一览
  5. 【BZOJ3224】Tyvj 1728 普通平衡树 Splay
  6. SQL Server优化技巧之SQL Server中的&quot;MapReduce&quot;
  7. re模块使用
  8. Java多线程性能优化
  9. 模仿GsonConverter 写的StringConverter 解析String字符串
  10. java面向对象基础(二)
  11. java的&lt;&lt;左移,&gt;&gt;右移,&gt;&gt;&gt;无符号右移
  12. Java异常封装(自己定义错误码和描述,附源码)
  13. Mysql精华版(命令大全)
  14. shell从入门到精通进阶之一:Shell基础知识
  15. HDU1659-GCD-容斥原理
  16. 自动化web前端测试,自动登录网站.目前发现最靠谱的方法是imacros
  17. Unity中UGUI鼠标穿透UI问题的解决方法
  18. Linux系统——程序员跳槽必备
  19. Microsoft Visual Studio 2010(vs10)安装与使用
  20. Python 闭包(Closure)

热门文章

  1. RabbitMQ - 介绍
  2. post方式发送接收文件
  3. rpm的参数
  4. java 从Excel 输出和输入
  5. ImportError: No module named bs4错误解决方法
  6. 关于JQuery animate()方法
  7. awk日志分析
  8. Http重要知识点
  9. C# GDI+ 利用 Rectangle GraphicsPath 判断 矩形或多边形 图形关系
  10. 精通Groovy