广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot@DeleteMapping(/xxx/{id})请求报405的解决
  • 208
分享到

SpringBoot@DeleteMapping(/xxx/{id})请求报405的解决

Python 官方文档:入门教程 => 点击学习

摘要

目录SpringBoot@DeleteMapping(/xxx/{id})请求报405springBoot---@DeleteMapping@DeleteMapping总结Sprin

SpringBoot@DeleteMapping(/xxx/{id})请求报405

学习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

SpringBoot---@DeleteMapping

@DeleteMapping

在编写代码时引用了*@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文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作