开发者

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

开发者 https://www.devze.com 2023-01-13 10:29 出处:网络 作者: 薛定谔的猿...
目录SpringBoot@DeleteMapping(/xxx/{id})请求报405SpringBoot---@DeleteMapping@DeleandroidteMapping总结SpringBo编程客栈ot@DeleteMapping(/xxx/{id})请求报405
目录
  • SpringBoot@DeleteMapping(/xxx/{id})请求报405
  • SpringBoot---@DeleteMapping
    • @DeleandroidteMapping
  • 总结

    SpringBo编程客栈ot@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@DeleteMapping(/xxx/{id})请求报405的解决

    然后我们需要在springBoophpt的配置文件中将它手动开启即可;

    spring.mvc.hiddenmethod.filter.enabled=trueandroid

    SpringBoot---@DeleteMapping

    @DeleteMapping

    在编写代码时引用了*@DeleteMapping*注解

    @DeleteMapping(value = "/remove/{courseNo}" )
      public String remove(@PathVariable("courseNo") String courseNo){
        coursjseService.removeCourseByNo(courseNo);
        return "redirect:/course/list";

    但运行程序页面无结果返回,出现POST错误。经百度查询,Spring系统配置hiddenmethod过滤器默认是False,解决结果在application.properties添加一行代码,启用过滤器:

    spring.mvc.hiddenmethod.filter.enabled=true

    总结

    以上为个人经验,希望能给大家一个参考,也希望大开发者_C教程家多多支持我们。

    0

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    关注公众号