Python 官方文档:入门教程 => 点击学习
目录SpringBoot@DeleteMapping(/xxx/{id})请求报405springBoot---@DeleteMapping@DeleteMapping总结Sprin
在学习SpringBoot2.x实现 restful 的delete操作时发现在表单中添加
<input type="hidden" name="_method" value="delete"/>
后台用@deleteMapping(/xxx/{id})这种方式会报405(不允许的访问方式)
各种百度,后来发现在 Spring Boot 的 META-INF/spring-configuration-metadata.JSON 配置文件中,默认是关闭Spring 的 hiddenmethod 过滤器的
然后我们需要在springBoot的配置文件中将它手动开启即可;
spring.mvc.hiddenmethod.filter.enabled=true
在编写代码时引用了*@DeleteMapping*注解
@DeleteMapping(value = "/remove/{courseNo}" )
public String remove(@PathVariable("courseNo") String courseNo){
courseService.removeCourseByNo(courseNo);
return "redirect:/course/list";
但运行程序页面无结果返回,出现POST错误。经百度查询,Spring系统配置hiddenmethod过滤器默认是False,解决结果在application.properties添加一行代码,启用过滤器:
spring.mvc.hiddenmethod.filter.enabled=true
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: SpringBoot@DeleteMapping(/xxx/{id})请求报405的解决
本文链接: https://www.lsjlt.com/news/177497.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0