软件编程
位置:首页>> 软件编程>> java编程>> SpringBoot@DeleteMapping(/xxx/{id})请求报405的解决

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

作者:薛定谔的猿...  发布时间:2022-06-13 14:00:48 

标签:SpringBoot,@DeleteMapping(/xxx/{id}),请求,405

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


然后我们需要在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

来源:https://blog.csdn.net/qq_33879627/article/details/106554777

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com