当前位置:网站首页>@RequestParam,@PathVariable两个注解的区别
@RequestParam,@PathVariable两个注解的区别
2022-07-26 00:09:00 【qq_25073223】
转自:
@RequestParam,@PathVariable两个注解的区别
下文笔者讲述@RequestParam,@PathVariable三个注解的不同之处,如下所示:
@RequestParam @PathVariable注解的功能: 用于从request中接收请求的,两个都可以接收参数 @RequestParam @PathVariable注解的区别: @RequestParam 是从request里面拿取值 @PathVariable 是从一个URI模板里面来填充 例:
@RequestParam示例分享
http://localhost:8080/springmvc/test/888?param1=999¶m2=666
使用以上的URL获取参数信息,如下所示:
public String getInfo(
@RequestParam(value="param1", required=true) String param1,
@RequestParam(value="param2", required=false) String param2){
//
}
@RequestParam 支持下面四种参数
defaultValue: 如果本次请求没有携带这个参数,或者参数为空,那么就会启用默认值
name:绑定本次参数的名称,要跟URL上面的一样
required:这个参数是不是必须的
value:跟name一样的作用,是name属性的一个别名
例:
@PathVariable
http://localhost:8080/springmvc/test/888?param1=999¶m2=666
@RequestMapping("/test/{id}")
public String getInfo(@PathVariable(value="id") String id,
@RequestParam(value="param1", required=true) String param1,
@RequestParam(value="param2", required=false) String param2){
//id的值为888
}边栏推荐
- STM32 serial port
- LeetCode_55_跳跃游戏
- Leetcode high frequency question 66. add one, give you an array to represent numbers, then add one to return the result
- MySQL - database log
- 多任务编程
- 没错,请求DNS服务器还可以使用UDP协议
- Solid smart contract development - 3.2-solid syntax array, structure, mapping
- Yolov4 tiny network structure
- "Animal coin" is fierce, trap or opportunity? 2021-05-12
- STM32 pit encountered when using timer to do delay function
猜你喜欢

“动物币”凶猛,陷阱还是机遇?2021-05-12

FreeMarker view integration

MPLS实验

MySQL——数据库日志

The items of listview will be displayed completely after expansion

对“DOF: A Demand-oriented Framework for ImageDenoising“的理解

网站服务器停止响应是什么意思?

MySQL——主从复制
34 use of sparksql custom functions, architecture and calculation process of sparkstreaming, dstream conversion operation, and processing of sparkstreaming docking Kafka and offset

"Animal coin" is fierce, trap or opportunity? 2021-05-12
随机推荐
初阶C语言 - 分支语句(if、switch)
How does the server build a virtual host?
Backtracking - 77. combination
网站服务器停止响应是什么意思?
[one library] mapbox GL! A map engine out of the box
Detailed explanation of kubernetes network plug-ins - calico chapter - Overview
YoloV4-tiny网络结构
LeetCode_ 55_ Jumping game
Get JD product details original data API
CountDownLatch
IP核:PLL
Unified handling of global exceptions
Elementary C language - branch statements (if, switch)
MySQL——多版本并发控制(MVCC)
12.神经网络模型
FreeRTOS personal notes - mutex
FreeRTOS个人笔记-消息队列
服务器如何搭建虚拟主机?
Binary tree - 530. Minimum absolute difference of binary search tree
Binary tree - 226. Flip binary tree