注解之@PathVariable
@PathVariable只支持一个属性value,类型是为String,代表绑定的属性名称。默认不传递时,绑定为同名的形参。
用来便捷地提取URL中的动态参数。其英文注释如下:
Annotation which indicates that a method parameter should be bound to a URI template variable. Supported for {@link RequestMapping} annotated handler methods in Servlet environments.
应用时,在@RequestMapping请求路径中,将需要传递的参数用花括号{}括起来,然后,通过@PathVariable("参数名称")获取URL中对应的参数值。如果@PathVariable标明参数名称,则参数名称必须和URL中参数名称一致。
@RequestMapping("/viewUser/{id}/{name}")
public Map<String, Object> viewUser(@PathVariable("id") Integer idInt, @PathVariable Integer name) {
System.out.println("@PathVariable中 请求参数 id = " + idInt);
Map<String, Object> user = new HashMap<>();
user.put("id", idInt);
user.put("name", name);
return user;
}
/**
* @Title viewUser2
* @Description @PathVariable未标注参数名称,则被注解参数名必须后URL中的一致
* @date 2018-12-15 11:08
*/
@RequestMapping("/owners/{ownerId}")
public Map<String, Object> viewUser2(@PathVariable Integer ownerId) {
System.out.println("@PathVariable中 请求参数 ownerId = " + ownerId);
Map<String, Object> user = new HashMap<>();
user.put("id", ownerId);
user.put("name", "Lucy");
return user;
}
URI 模板 “/owners/{ownerId}” 指定了一个名叫 ownerId的变量。当控制器处理这个请求时,ownerId的值被设置为从 URI 中解析出来。比如,当请求 /viewUser/100 进来时,100 就是 ownerId的值。
注解之@PathVariable的更多相关文章
- 【spring boot】注解@ApiParam @PathVariable @RequestParam三者区别
1.@ApiParam,就是用于swagger提供开发者文档,文档中生成的注释内容. @ApiOperation( value = "编辑公告", notes = "编辑 ...
- 阶段3 3.SpringMVC·_03.SpringMVC常用注解_3 PathVariable注解
请求地址都一样,根据不同的请求方式,最终让不同的方法去执行.这就是restfull的风格 如果有两个查询都是get的.那么当前访问 满足条件的就是两个. 用一个占位符 {id} 演示PathVaria ...
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
文章主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用. 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request ...
- SpringMVC @RequestBody @RequestParam @PathVariable 等参数绑定注解详解
request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: http://blog.csdn.net/walkerjong/article/details/794 ...
- 11.@RequestParam @RequestBody @PathVariable 等参数绑定注解详解
对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: handler method ...
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解(转)
引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: han ...
- (转)@RequestParam @RequestBody @PathVariable 等参数绑定注解详解
引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后,该篇主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用: 简介: han ...
- 【转】@RequestParam @RequestBody @PathVariable 等参数绑定注解详解
@RequestParam @RequestBody @PathVariable 等参数绑定注解详解 2014-06-02 11:24 23683人阅读 评论(2) 收藏 举报 目录(?)[+] 引言 ...
- Spring MVC常用注解@PathVariable、@RequestHeader、@CookieValue、@RequestParam、@RequestBody、@SessionAttributes、@ModelAttribute
简介: handler method参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型) A.处理requet uri部分(这里指uri template中 ...
随机推荐
- WebMisCentral-Client 适配MySql数据库
由于本身WebMisCentral采用的是EF5.0,所以适配起来还是非常简单的,下面看操作: 1.ElegantWM.WebUI层中(或者ElegantWM.DAL)通过NUGET下载MySQL.D ...
- vue与自定义元素的关系
你可能已经注意到 Vue.js 组件非常类似于自定义元素--它是 Web 组件规范的一部分.实际上 Vue.js 的组件语法参考了该规范.例如 Vue 组件实现了 Slot API 与 is 特性.但 ...
- 快播王欣发布匿名IM社交软件“马桶MT”
2019年1月14日,快播王欣推出了一款匿名IM社交软件——马桶MT,它的灵感像是来自于美国的匿名分享应用Secret(已关闭). 原快播创始人王欣近日在微博预告了其新公司云歌人工智能推出一款全新社交 ...
- Android集成Google地图详细步骤记录
先贴下Google官方的地图demo地址:https://github.com/googlemaps/android-samples 那么接下来第一步,申请Google的API key. 使用谷歌账号 ...
- Nginx 基本命令
基础命令 1.启动 直接点击Nginx目录下的nginx.exe 或者 cmd运行start nginx 2.关闭 nginx -s stop 或者 nginx -s quit stop表示立即停止n ...
- jQuery移除或禁用html元素点击事件常用方法小结
移除或禁用html元素的点击事件可以通过css实现也可以通过js或jQuery实现. 一.CSS方法 .disabled { pointer-events: none; } 二.jQuery方法 方法 ...
- [Model] AlexNet
CaffeNet - a variant of AlexNet Ref: Classification: Instant Recognition with Caffe This is caffeNet ...
- web.xml配置DispatcherServlet (***-servlert.xml)
1. org.springframework.web.servlet.DispatcherServlet 所在jar包: <dependency> <groupId>org.s ...
- js - 移动端的超出滚动功能,附带滚动条,可解决弹层中滚动穿透问题。
背景: 弹层里边有可滚动区域时,在移动端的坑我就不多说了. 找了很多解决滚动穿透的方案,最终都不能完美解决. 一气之下自己js撸了一个. 效果图: 原理: 1.解决滚动穿透:通过给弹层绑定touchm ...
- SQL Server2008 删除登录记录
SQL Server Management Studio登陆窗口 清空这些多余的登陆名 主要是删除SqlStudio.bin文件 WinXP: C:\Documents and Set ...