SpringBooot页面访问出现GET/POST请求不支持,404页面问题

最近在学习SpringBoot,在页面访问上总是遇到一些问题,今天抽个时间总结一些遇到的几种情况,希望有所帮助。

GET/POST请求不支持

org.springframework.web.HttpRequestMethodNotSupportedException:
Request method 'GET' /'POST'not supported

1.确认页面与Controller是否使用了不同的请求方式,如果你是用的是RequestMapping,或者页面默认的请求方式,数据发送方式都默认为Get请求,会将数据放在url中发送,

2.确认前后端数据参数名类型等是否一致,不一致的参数类型也会导致请求不支持

3.请求路径是否正确?

4.数据格式问题,你所传递的数据格式是否为Get/Post格式

5.如果你使用了2.x以上版本的springboot且用了Thymeleaf,检查你的pom中是否有过更改版本。以下行为会导致冲突问题

如果你使用了版本增强的话,可以去掉了,在springboot新版本中已经将Thymeleaf默认支持版本提升到3.0.11

<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
可以在这里找到springboot的默认版本信息
/spring-boot-dependencies/2.2.6.RELEASE/spring-boot-dependencies-2.2.6.RELEASE.pom:9

博主所使用的SpringBoot的默认Thymeleaf版本信息


 <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
    <thymeleaf-extras-data-attribute.version>2.0.1</thymeleaf-extras-data-attribute.version>
    <thymeleaf-extras-java8time.version>3.0.4.RELEASE</thymeleaf-extras-java8time.version>
    <thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
    <thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>

404页面问题

1.检查你的主函数是否在Controller在同一及目录或父目录下

2.检查Controller中的路径,注解,映射

3.是否使用了Thymeleaf模板,如果使用是否放在了默认的静态资源路径下.

4.有没有在application文件中加入server.servlet.context-path=/xxx访问前缀

5.Thymeleaf版本冲突会导致你能够进入Controller并执行其中代码,但无法返回正确的页面

6.如果自设了拦截器,检查拦截器是否拦截了你的访问路径

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值