当前位置:网站首页>@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
}边栏推荐
猜你喜欢

Duplicate disk: recommended system - negative sampling strategy

Yolov4 tiny network structure

LeetCode高频题66. 加一,给你一个数组表示数字,则加1返回结果

Binary tree -- 104. Maximum depth of binary tree

NVIDIA cudnn learning

C语言实战之猜拳游戏

Js理解之路:Js常见的6中继承方式

Stm32- analyze latency based on assembly

Shib (firewood Dog Coin) rose hundreds of times in January. What core elements does a hundred times coin need? 2021-05-09

Nest.js 用了 Express 但也没完全用
随机推荐
Elementary C language - branch statements (if, switch)
Prometheus operation and maintenance tool promtool (II) query function
OPENCV学习DAY6
Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK
"Demons dance", is the bull market over? 2021-05-13
FreeMarker view integration
MySQL——主从复制
Unity -- Euler angle, quaternion
软件测试同行评审到底是什么?
Android solves the risk of database injection vulnerability
合肥提前批
【一库】mapbox-gl!一款开箱即用的地图引擎
Binary tree - 530. Minimum absolute difference of binary search tree
Unified handling of global exceptions
How does the server build a virtual host?
Backtracking - 77. combination
34 use of sparksql custom functions, architecture and calculation process of sparkstreaming, dstream conversion operation, and processing of sparkstreaming docking Kafka and offset
This time, thoroughly understand promise principle
J9数字论:什么是DAO模式?DAO发展过程的阻碍
"Animal coin" is fierce, trap or opportunity? 2021-05-12