@RequestParam和@PathVariable的区别
2024-08-31 02:25:10
一:@RequestParam
@RequestParam是传递参数的.
@RequestParam用于将请求参数区数据映射到功能处理方法的参数上。
public Object Login(@RequestParam(value = "name",defaultValue = "lisi") String name, @RequestParam("password")String password)
在URL中发送请求:http://localhost:8080/welcome?name=lisi&&password=1234
defaultValue是默认值。现在是默认为"lisi"。如果请求的name=zhangsan。是以实际的请求为准的。
二:@PathVariable
@PathVariable绑定URI模板变量值
@RequestMapping(value="/users/{userId}/topics/{topicId}")
public String test( @PathVariable(value="userId") int userId, @PathVariable(value="topicId") int topicId)
如请求的URL为“控制器URL/users/123/topics/456”,则自动将URL中模板变量{userId}和{topicId}绑定到通过@PathVariable注解的同名参数上,即入参后userId=123、topicId=456。代码在PathVariableTypeController中
1):
@RequestParam是自己写给URL的。作为参数。
@PathVariable是从URL中取到的值。作为Controller中入参。
2):
@RequestParam
是从request里面拿取值,
@PathVariable
是从一个URI模板里面来填充
最新文章
- 切换“使用被动式FTP”
- TypeError: coercing to Unicode: need string or buffer, ChatRoom found
- MATLAB 绘图时的相关心得
- hdu 1057 (simulation, use sentinel to avoid boudary testing, use swap trick to avoid extra copy.) 分类: hdoj 2015-06-19 11:58 25人阅读 评论(0) 收藏
- 关于mysql的错误 - no query specified
- NAT,网络地址转换详解
- vb.net之窗体继承
- rundeck email配置文件配置
- 树状数组(BIT)
- 【MSP是什么】MSP认证之项目管理与项目群管理的区别
- - 通过 UIBezierPath 做一个中空的扫描器
- Android PopupWindow菜单
- 项目中ApplicationContext
- Shiro中的授权问题(二)
- SMB协议原理抓包分析
- flink1.7 checkpoint源码分析
- SpriteKit 关于categoryBitMask collisionBitMask contactTestBitMask 遇到的一些问题
- DJANGO ADMIN 一些有用的设置(转)
- Swift3 颜色转换成图片Image
- 【线段树】【P4198】 楼房重建
热门文章
- PHP 三元运算符?:的小坑
- if isinstance(obj, int):
- FTP 服务器搭建(基于 CentOS 7)
- MySQL 基准测试
- EF框架之——Code First以及踩过的这些“坑”
- Convolutional Neural Networks(5):Pooling Layer
- [eclipse中使用Git插件] 008 - git操作pull、merge、stash、commit
- Eclipse常见版本和JDK常用版本对应关系
- BZOJ 3262(Treap+树状数组)
- Mybatis-技术专区-Mapper接口以及Example的实例函数及详解