zoukankan      html  css  js  c++  java
  • org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported

    错误场景:今天使用SpringBoot编写登入和注册的时候一直报错org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported,405,我当时就奇怪了为什么我用Post方法,为什么会出现一个Get请求不被支持

    关键代码:

    静态页
    <body>
    <form action="/manager/login" method="post">
        用户名:<input name="manname" type="text"/><br>
        密码:<input name="manpass" type="password"> <br>
        <input type="submit" value="登录">
    </form>
    </body>
    
    
    <body>
    <form action="/manager/regist" method="post">
        用户名:<input name="manname" type="text"/><br>
        密码:<input name="manpass" type="password"> <br>
        <input type="submit" value="注册">
    </form>
    </body>

    看了很多博客,各种解决方法

    版本问题【这个不好评价】

    把POST方法改为Get方法【这个我已经无力吐槽了,POST和GET方法的区别,不懂的萌新自己去查】

    最后还是别人的一句评论让我解决了这个方法

    @POSTMapping改为@RequestMapping

     附加,一个为什么勉强可以解释为什么可以解决这个问题的原因

    @GetMapping
    用于将HTTP GET请求映射到特定处理程序方法的注释。具体来说,@GetMapping是一个作为快捷方式的组合注释
    @RequestMapping(method = RequestMethod.GET)。

    @PostMapping
    用于将HTTP POST请求映射到特定处理程序方法的注释。具体来说,@PostMapping是一个作为快捷方式的组合注释@RequestMapping(method = RequestMethod.POST)。

    @RequestMapping:
    一般情况下都是用@RequestMapping(method=RequestMethod.),因为@RequestMapping可以直接替代以上两个注解,但是以上两个注解并不能替代@RequestMapping,@RequestMapping相当于以上两个注解的父类!

  • 相关阅读:
    对我最重要的三个老师
    究竟 javascript 错误处理有哪些类型?
    前端小白凭什么杀进 BAT?
    金九银十,换工作热潮来临!
    适用于Java开发人员的SOLID设计原则简介
    在5分钟内将Spring Boot作为Windows服务启动
    Redis中的Java分布式缓存
    Arrays工具类详解
    SpringBoot整合redis
    java 数组用法详解
  • 原文地址:https://www.cnblogs.com/hahayixiao/p/13251796.html
Copyright © 2011-2022 走看看