org.springframework.web.bind.MissingServletRequestParameterException

org.springframework.web.bind.missingservletrequestparameterexception org springframework web bind

Problem occurs

When testing the interface .



Introduction / analysis

An interface has been implemented :

package com.ybqdren.controller.center;
import com.ybqdren.pojo.Users;
import com.ybqdren.service.center.CenterUserService;
import com.ybqdren.utils.IMOOCJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Wen(Joan) Zhao <[email protected]>
* 2021/11/9
*/
@Api(value = "center - User center ",tags = {" Relevant interfaces displayed in the user center "})
@RestController
@RequestMapping("center")
public class CenterController {
@Autowired
private CenterUserService centerUserService;
@ApiOperation(value = " Get user information ",notes = " Get user information ",httpMethod = "GET")
@GetMapping("userinfo")
public IMOOCJSONResult userinfo(
@ApiParam(name = "userId",value=" user id",required = true)
@RequestParam String userid
){
Users user = centerUserService.queryUserInfo(userid);
return IMOOCJSONResult.ok(user);
}
}

Here we use the request Parameter annotation RequestParam, Used to obtain :

http://localhost:8080/center/userinfo/userid=xxx

Request parameters in this form .

Because here we are not in RequestParam The name of the parameter specified in the annotation , therefore SpringBoot Will default to url Looking for a person named userid Parameters of .



Problem solving

Problem location

According to... In the error :

MissingServletRequestParameterException

It can be seen that it is the problem of parameter transfer .

Look again :

Required request parameter 'userid' for method parameter type String is not present]

Will find , A place called userid There is a problem with the parameters of .


Check the parameter name passed in from the front end :

serverUrl + '/center/userInfo?userId=' + userInfo.id,

Review the briefing / Analyzing , We didn't specify RequestParam The parameter name that the annotation accepts , So it's in url What I'm looking for is a man called userid Parameters of , So I didn't find it .



Solution

Therefore, we can solve it in the following three ways :

  1. Modify the parameter name passed in from the front end ( The learning environment can be used , But the least recommended )
  2. Modify the parameter name of the current routing method
  3. stay RequestParam Set in annotation name Value ( The best way )
版权声明
本文为[Zhao Wen_ Back end development engineer]所创,转载请带上原文链接,感谢
https://javamana.com/2021/11/20211109073233509s.html

  1. 应急响应入门之Linux分析排查
  2. Twitter如何升级Hadoop+Kafka架构实现实时处理数十亿个事件?
  3. 引人入胜,实战讲解“Java性能调优六大工具”之linux命令行工具
  4. docker 查看实时日志
  5. JFrog Artifactory 7.27 上传应用到私服和从maven私服下载制品
  6. Ces protocoles http simples
  7. [including thesis + source code] JavaWeb hospital triage registration management system SSH [package running successfully]
  8. Java初学者,想知道如何用if语法当条件成立后什么都不执行,否则执行动作
  9. 体验.NET Core使用IKVM对接Java
  10. 深入JavaScript高级语法-coderwhy
  11. 排序算法--Java实例/原理
  12. 停止docker时报错:Warning: Stopping docker.service, but it can still be activated by: docker.socket
  13. 【完整示例】采用jenkins pipeline实现自动构建并部署至k8s
  14. 【Linux】腾讯云服务器,使用FRP内网穿透,端口映射,远程访问内网ubuntu机器
  15. 关于#java#的问题:resultMap type映射不到我想要的类 只能映射java的内部类 加了全路径也映射不了 怎么解决
  16. 排序算法--Java實例/原理
  17. 就这一次,阿里最新出品源码阅读指南,一套搞定JDK+vm源码
  18. 两个小时手写了个Zookeeper分布式服务注册中心
  19. Algorithme de tri - - instance / principe Java
  20. Plongez dans la syntaxe avancée javascript - coderwhy
  21. JavaScript高级程序设计读后感(一)之零碎知识点查漏补缺
  22. 先到先学!Alibaba甩出第四次更新的JDK源码高级笔记(终极版)
  23. Java File类
  24. How To Install MariaDB on linux
  25. #yyds干货盘点# Mybatis 的 XML 配置
  26. Spring认证中国教育管理中心-Spring Data MongoDB教程七
  27. Linux进程和任务管理
  28. Linux文件系统日志分析
  29. Redis-客户端-重点知识
  30. Redis-事件-重点知识
  31. Redis-AOF持久化-重点知识
  32. Redis-RDB持久化-重点知识
  33. http://lx.gongxuanwang.com/sszt/32.htm
  34. 回顾我两个月面试阿里,携程,小红书,美团,网易等等(Java岗)
  35. JavaScript高级程序设计读后感(一)之零碎知识点查漏补缺
  36. Rocketmq source code analysis: message sending process
  37. Rocketmq source code analysis: how does rocketmq store messages?
  38. RocketMQ source analysis: how to debug the RocketMQ source in IDEA
  39. How To Install MariaDB on linux
  40. Comment installer mariadb sur Linux
  41. http://lx.gongxuanwang.com/sszt/7.htm
  42. Classe de fichiers Java
  43. Premier arrivé, premier servi! Alibaba lance la quatrième mise à jour de JDK source Advanced notes (Ultimate)
  44. #yyds干货盘点#设计模式之【工厂模式】
  45. Java * SpringBoot实现万能文件在线预览,已开源,真香
  46. Redis | 第4章 Redis中的数据库《Redis设计与实现》
  47. Liang Tingwei's first variety show of "director, please give advice" reshapes the classic work "spring of a new town"
  48. Redis | 第4章 Redis中的数据库《Redis设计与实现》
  49. 关于centos docker版本过低导致 is not a valid repository/tag: invalid reference format
  50. Redis 源码简洁剖析 02 - SDS 字符串
  51. 回顧我兩個月面試阿裏,攜程,小紅書,美團,網易等等(Java崗)
  52. Rétrospectivement, j'ai passé deux mois à interviewer Ali, ctrip, Little Red Book, meituan, NetEase, etc. (Java post)
  53. Docker + webhook Automation Deployment Front End Project
  54. Java技术之Spring、Hibernate框架整合方法
  55. http://lx.gongxuanwang.com/sszt/32.htm
  56. 亚马逊自己的 Linux 发行版现在完全基于 Fedora 了
  57. Redis 源码简洁剖析 02 - SDS 字符串
  58. Java技術之Spring、Hibernate框架整合方法
  59. Méthode d'intégration des cadres de printemps et d'hibernation de la technologie Java
  60. Redis source Concise Analysis 02 - SDS String