当前位置:网站首页>@RequestParam使用
@RequestParam使用
2022-08-02 07:29:00 【sebeefe】
1、加与不加的区别
@RequestMapping("/list1")
public String test1(int userId) {
return "list";
}
@RequestMapping("/list2")
public String test2(@RequestParam int userId) {
return "list";
}
(1)不加@RequestParam前端的参数名需要和后端控制器的变量名保持一致才能生效
(2)不加@RequestParam参数为非必传,加@RequestParam写法参数为必传。但@RequestParam可以通过@RequestParam(required = false)设置为非必传。
(3)@RequestParam可以通过@RequestParam(“userId”)或者@RequestParam(value = “userId”)指定传入的参数名。
(4)@RequestParam可以通过@RequestParam(defaultValue = “0”)指定参数默认值
(5)如果接口除了前端调用还有后端RPC调用,则不能省略@RequestParam,否则RPC会找不到参数报错
(6)访问时:
- 不加@RequestParam注解:url可带参数也可不带参数,输入 localhost:8080/list1 以及 localhost:8080/list1userId=xxx 方法都能执行
- 加@RequestParam注解:url必须带有参数。也就是说你直接输入localhost:8080/list2 会报错,不会执行方法。只能输入localhost:8080/list2userId=xxx 才能执行相应的方法
先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。深知大多数初中级java工程师,想要升技能,往往是需要自己摸索成长或是报班学习,但对于培训机构动则近万元的学费,着实压力不小。自己不成体系的自学效率很低又漫长,而且容易碰到天花板技术停止不前。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- postgres groupby 合并字符串
- MySQL优化之慢日志查询
- Transimpedance amplifier
- uniapp 禁止默认返回事件
- WebRTC系列-SDP之编码信息收集
- MySQL batch update
- apt & apt-get commands
- 59: Chapter 5: Develop admin management services: 12: MongoDB usage scenarios; (non-core data, non-core data with a relatively large amount of data, small private files such as face photos;)
- 5分钟搞懂MySQL - 行转列
- postgres groupby merge strings
猜你喜欢
随机推荐
flutter解决键盘和输入框不适配问题
7.联合索引(最左前缀原则)
Kind of weird!Access the destination URL, the host can container but not
[Unity3D] Beginner Encryption Skills (Anti-Cracking)
(2022 Niu Ke Duo School 5) B-Watches (two points)
MySQL - Detailed Explanation of Database Transactions
CollectionUtil: a collection of functional style tool
MGRE综合实验
多表的查询
HCIP第一天
HCIP 第十一天
有点奇怪!访问目的网址,主机能容器却不行
【Network】IP, subnet mask
playwright 爬虫使用
Inverter Phase Locking Principle and DSP Implementation
Introduction to Totem Pole and Push-Pull Circuits
LeetCode 2312. Sell Wood Blocks
UG NX二次开发(C#)-外部模式-导出dwg格式的文件
MySQL error 1055 solution: [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
MGRE环境下的OSPF