文章目录
https://www.bilibili.com/video/av49996848?p=8
@RequestMapping
params 参数
headers
value
@PathVariable
REST 风格
HiddenHttpMethodFilter - 拦截 delete、put 请求
原理:
操作:
web.xml 中添加
<!-- 配置 org.springframework.web.filter.HiddenHttpMethodFilter: 可以把 POST 请求转为 DELETE 或 PUT 请求-->
<filter>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
<filter-name>HiddenHttpMethodFilter</filter-name>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
index.jsp 中添加( 假装不知道 ajax )
<form action="test/delete" method="post">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" value="Test DELETE">
</form>
<form action="tetst/put" method="post">
<input type="hidden" name="_method" value="put">
<input type="submit" value="Test PUT">
</form>
controller 中添加
@Controller
public class HelloWorld {
@ResponseBody //返回字符串(不进行渲染)
@DeleteMapping("/test/delete")
public String testDelete() {
return "delete" ;
}
@ResponseBody
@PutMapping("/test/put")
public String testPut() {
return "put" ;
}
}