当前位置:网站首页>@RequestParam使用
@RequestParam使用
2022-07-28 16:25: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 才能执行相应的方法
边栏推荐
- UNIQUE VISION Programming Contest 2022(AtCoder Beginner Contest 248)G. GCD cost on the tree
- kubernetes service 原理解析
- The practice of beego framework in goweb development: Section I Introduction to beego framework
- MySQL PgSQL realizes the merging of multiple lines of records into one line, grouping and merging, and dividing with specified characters
- 高速电路中电感的选型和应用
- Atcoder beginer contest 240 g.reporting Takahashi (classical problems of Combinatorial Mathematics)
- Shell脚本之免交互操作
- Verilog 每日一题(VL14 自动贩售机1--FSM常见题型)
- 线性代数及矩阵论(十)
- Firewalld防护墙
猜你喜欢

The actual combat of the beego framework of goweb development: Section III program execution process analysis

Selection of resistance in high speed circuit

Verilog daily question (vl5 signal generator)

Visual Studio 2012/2015发布Web应用连同.cs源码一起发布

Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)

How do we do full link grayscale on the database?

异步FIFO基本原理(基于Verilog的简单实现)

Verilog daily question (vl29 single port RAM)

Selection and application of capacitor in high speed circuit -- detailed explanation

net框架
随机推荐
GEAR: Graph-based Evidence Aggregating and Reasoning for Fact Verification
Andthen of function interface
The maximum recommended number of rows for MySQL is 2000W. Is it reliable?
线性代数及矩阵论(七)
Use Alibaba cloud's free SSL certificate
零基础利用Unity3D开发AR应用并远程下载3D模型
《Kubernetes》你需要掌握的 Service 和 Ingress
Round 1A 2022 - Code jam 2022 c.weightlifting (interval DP)
Verilog daily question (vl8 uses generate... For statement to simplify code)
Verilog daily question (vl27 settable counter)
The 2021 ICPC ASIA Taipei Regional programming contest L. leadfoot (combinatorics /2-adic assignment function +kummer theorem)
线性代数及矩阵论(八)
Microservice Architecture - service registry and service gateway (6.8) (Reprint)
Verilog 每日一题(VL4 移位运算与乘法)
Codeworks round 801 (Div. 2) and epic Institute of technology round D. tree queries (tree DP)
Iris framework practice of goweb development: project summary and review
Verilog 每日一题 (VL30 RAM的简单实现)
Shell编程之Sed
【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
Zero foundation uses unity3d to develop AR applications and download 3D models remotely