当前位置:网站首页>@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 才能执行相应的方法
边栏推荐
- Visual Studio 2015 团队开发之Azure DevOps篇
- wpf命令按钮透明样式
- Verilog 每日一题(VL6 数据串转并电路)
- C # traversal set
- 我为什么选择使用Go语言?
- Verilog daily question (vl8 uses generate... For statement to simplify code)
- Shell编程之Sed
- Differences between CNSA and CASC and CASIC
- 【ansible】ansible shell 执行远程命令遇到awk 中$符号的问题
- Jupyter notebook win installation record
猜你喜欢

Classroom attendance system based on QT design (using RDS for MySQL cloud database)

Visual Studio 2015 团队开发之Azure DevOps篇

Zero foundation uses unity3d to develop AR applications and download 3D models remotely
![[CDH] configure CDH components through clouderamanager and collect JMX information with Prometheus monitoring](/img/6a/bbc1ab0cfae9139308da4ded1376a8.png)
[CDH] configure CDH components through clouderamanager and collect JMX information with Prometheus monitoring

在android开发过程中遇到.sqlite文件处理

Source code of voice live broadcast app

Analysis of kubernetes service principle

How do we do full link grayscale on the database?

High speed circuit design practice -- Overview

Verilog daily question (vl14 vending machine 1 -- FSM common question types)
随机推荐
QR code generation of wechat applet with parameters
Shell脚本之免交互操作
C# 导入Excel文件数据的几种方法
SNAT、DNAT 防火墙规则的备份和还原
Verilog 每日一题 (VL30 RAM的简单实现)
WPF command button transparent style
Verilog 每日一题 (VL24 多bit MUX同步器 跨时域输出)
Role of Fortress machine
Basic principle of asynchronous FIFO (simple implementation based on Verilog)
Educational codeforces round 126 (rated for Div. 2) f.teleporters (two sets and two points)
C#遍历集合
Code implementation additive attention
带参数的微信小程序二维码生成
零基础利用Unity3D开发AR应用并远程下载3D模型
【impala】【报错解决】 Impala cannot read or execute the parent directory of dfs.domain.socket.path的解决方法
侦察机与预警机的区别
Using SQL server agent job to restore the database regularly
Linear algebra and matrix theory (VIII)
Fine-grained Fact Verification with Kernel GA Network
Goweb开发之Beego框架实战:第一节 Beego框架介绍