[org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'xx...

本文介绍了在SpringBoot项目中遇到POST请求参数缺失的问题,即RequiredStringparameter'xxx'isnotpresent异常。错误原因是请求参数与@RequestParam注解的value值不匹配,特别是存在空格导致的匹配失败。解决方法是确保请求参数与注解匹配,避免额外的空格或其他不必要的字符。
摘要由CSDN通过智能技术生成

1、Spring Boot项目,发起Post请求,解决Required String parameter xxx is not present类型异常。

1 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - WARN  - o.s.w.s.m.support.DefaultHandlerExceptionResolver - Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'xxx ' is not present]
2 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - org.springframework.web.servlet.DispatcherServlet - Completed 400 BAD_REQUEST
3 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - org.springframework.web.servlet.DispatcherServlet - "ERROR" dispatch for POST "/error", parameters={masked}
4 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
5 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - o.s.w.s.m.m.annotation.HttpEntityMethodProcessor - Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
6 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - o.s.w.s.m.m.annotation.HttpEntityMethodProcessor - Writing [{timestamp=Mon Mar 29 20:43:52 CST 2021, status=400, error=Bad Request, message=, path=/api/offlineE (truncated)...]
7 2021-03-29 08:43:52 - [http-nio-8082-exec-1] - DEBUG - org.springframework.web.servlet.DispatcherServlet - Exiting from "ERROR" dispatch, status 400

其实,这个错误九成的原因,就是请求参数和@RequestParam(value = "userName ", required = true) String userName,注解@RequestParam的value值不一样的,我写的就奇葩了,字符串后面加了空格。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值