请求的路径相同,通过改变请求的方式来对应增删改查
- GET:查
- POST:增
- PUT:修
- DELETE:删
原理
- 请求被HiddenHttpMethodFilter拦截
- 判断请求是否正常,是否是POST请求
- 获取**_method**的值,兼容PUT、DELETE、PATCH
- 使用装饰者模式requestWrapper重写getMethod方法,传入_method值
// application.properties
// 开启对隐藏方法PUT和DELETE的支持
spring.mvc.hiddenmethod.filter.enabled=true
// html
<form th:action="@{/user/user}" method="post">
<!-- 通过隐藏域实现put请求-->