当前位置:网站首页>@RequestParam使用
@RequestParam使用
2022-07-30 20:15:00 【葬心啊】
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开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。添加下方名片,即可获取全套学习资料哦
边栏推荐
- 推荐系统:概述【架构:用户/物品特征工程---->召回层---->排序层---->测试/评估】【冷启动问题、实时性问题】
- 网络安全实验环境搭建
- HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
- 利用go制作微信机器人
- TensorFlow2:概述
- MySQL 高级(进阶) SQL 语句 (一)
- 基于人脸的常见表情识别(1)——深度学习基础知识
- Oblique document scanning and character recognition (opencv, coordinate transformation analysis)
- flowable工作流所有业务概念
- Mysql索引特性(重要)
猜你喜欢
多线程获取官方汇率
MySQL 视图(详解)
MySQL大总结
PPT如何开启演讲者模式?PPT开启演讲者模式的方法
推荐系统:实时性【特征实时性:客户端实时特征(秒级,实时)、流处理平台(分钟级,近实时)、分布式批处理平台(小时/天级,非实时)】【模型实时性:在线学习、增量更新、全量更新】
[PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
Weak Banks to data conversion ability?Matt software help solve bank dilemma
canvas基础讲解加示例
To the operation of the int variable assignment is atom?
MySQL的DATE_FORMAT()函数将Date转为字符串
随机推荐
How to copy table structure and table data in MySQL
ELK log analysis system
树形结构:二叉树的递归非递归遍历、BST
ERROR 1045 (28000) Access denied for user 'root'@'localhost'Solution
在jOOQ中获取数据的多种不同方式
第04章 逻辑架构【1.MySQL架构篇】【MySQL高级】
MySQL的on duplicate key update 的使用
365天挑战LeetCode1000题——Day 044 按公因数计算最大组件大小 并查集
18.客户端会话技术Cookie
MySQL----多表查询
[PM only] Quickly count who else in the team has not registered and reported information, and quickly screen out the members of their own project team who have not completed the list of XXX work items
MySQL kills 10 questions, how many questions can you stick to?
并发与并行的区别
4年测试经验去面试10分钟就被赶出来了,面试官说我还不如应届生?都这么卷吗...
对int变量赋值的操作是原子的吗?
[Ask] SQL statement to calculate the sum of column 2 by deduplicating column 1?
excel数字如何转换成文本?excel表格数据转换成文本的方法
MySQL 高级(进阶) SQL 语句 (一)
MySQL database --- Addition, deletion, modification and query of MySQL tables (advanced)
历史上的今天:Win10 七周年;微软和雅虎的搜索协议;微软发行 NT 4.0