restful风格使用put,delete方法需要使用springmvc提供的过滤器HiddenHttpFilter进行过滤
<!-- 配置处理请求方式 put delete的HiddenHttpMethodFiler过滤器-->
<filter>
<filter-name>HiddenHttpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HiddenHttpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
将以上代码配置在web.xml中
在前端控制器中的@RequestMapping的属性method使用RequestMethod方法选择put
@RequestMapping(value = "/allStudent1",method = RequestMethod.PUT)
public String updateStudent(Student student){
studentService.updateStudent(student);
return "redirect:allStudent";
}
}
然后在前端对应的视图中将 POST方法改为put
<form th:action="@{/student/allStudent1}" method="post">
<input type="hidden" name="_method" value="put">