@pathvariable 注解
1.4. @PathVariable 注解
带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义
通过 @PathVariable 可以将 URL 中占位符参数绑定到控制器处理方法的入参中:URL 中的 {xxx} 占位符可以通过@PathVariable("xxx") 绑定到操作方法的入参中。
- /**
- * localhost:8080/springmvc/hello/pathVariable/bigsea
- * localhost:8080/springmvc/hello/pathVariable/sea
- * 这些URL 都会 执行此方法 并且将 <b>bigsea</b>、<b>sea</b> 作为参数 传递到name字段
- * @param name
- * @return
- */
- @RequestMapping("/pathVariable/{name}")
- public String pathVariable(@PathVariable("name")String name){
- System.out.println("hello "+name);
- return "helloworld";
- }
JSP(这里指定全路径):
- <h1>pathVariable</h1>
- <a href="${pageContext.request.contextPath}/hello/pathVariable/bigsea" > name is bigsea </a>
- <br/>
- <a href="${pageContext.request.contextPath}/hello/pathVariable/sea" > name is sea</a>
- <br/>
运行结果:
- hello bigsea
- hello sea
@pathvariable 注解的更多相关文章
- REST风格,@PathVariable注解
REST(Representational State Transfer,表述性状态转移)是一种软件风格.所谓的REST风格可以简单理解为:使用url表示资源时,每个资源都用一个独一无二的url来表示 ...
- @RequestMapping 和@ResponseBody 和 @RequestBody和@PathVariable 注解 注解用法
接下来讲解一下 @RequestMapping 和@ResponseBody 和 @RequestBody和@PathVariable 注解 注解用法 @RequestMapping 为url映射路 ...
- 【SpringMVC】---RequestMapping、Ant 路径、PathVariable 注解、HiddenHttpMethodFilter 过滤器、用 POJO 作为参数
一.web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi=&qu ...
- @PathVariable注解的使用和@Requestparam
一. @PathVariable @PathVariable这是一个路径映射格式的书写方式注解,在类映射路径的后加上/{对应方法参数中属性@PathVariable("code") ...
- @RequestParam,@RequestBody,@ResponseBody,@PathVariable注解的一点小总结
一.前提知识: http协议规定一次请求对应一次响应,根据不同的请求方式,请求的内容会有所不同: 发送GET请求是没有请求体的,参数会直接拼接保留到url后一并发送: 而POST请求是带有请求体的,带 ...
- @RequestParam,@RequestBody,@PathVariable注解还分不清吗?
前言 在使用 SpringMVC 开发时,经常遇到前端传递的各种参数,比如 form 表单,JSON 数据,String[] 数组,再或者是最常见的 String 字符串等等,总之大部分场景都是在标题 ...
- @PathVariable注解
spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便,复习下: . @Controller public class TestController { @Re ...
- Spring MVC @PathVariable注解
下面用代码来演示@PathVariable传参方式 @RequestMapping("/user/{id}") public String test(@PathVariable(& ...
- @PathVariable注解的使用
带占位符的 URL 是 Spring3.0 新增的功能,该功能在SpringMVC 向 REST 目标挺进发展过程中具有里程碑的意义. 通过 @PathVariable 可以将 URL 中占位符参数绑 ...
随机推荐
- Not a million dollars ——a certain kind of ingenuity, discipline, and proactivity that most people seem to lack
原文:http://ryanwaggoner.com/2010/12/you-dont-really-want-a-million-dollars/a certain kind of ingenuit ...
- 1.3 selenium IDE录制脚本转换为其他代码格式
1.在seleniumIDE录制框中点击Options->options... 在Enable experimental features前打对勾,点击确定.
- Nested weights are bad for performance
警告信息“Nested weights are bad for performance”的消除方法 原因分析:在布局进行嵌套使用时,父布局与子布局都使用了android:layout_weight,但 ...
- 项目整体说明及WBS练习
乐谱识别研究的意义 纸质乐谱向数字化乐谱的转换,是人类音乐活动与计算机音乐处理之间进行信息交流的必经之路.光学乐谱识别是将纸质乐谱扫描输入计算机后,对乐谱图像加以处理.识别.分析,最终获得乐谱的计算机 ...
- 如何将CAD文件导入到Protel和PADS中
一. 如何把CAD中的板框图纸导入到Protel中? a. 在CAD中单位设置为“毫米”,并做简单的处理,板框图是有合并还是分解都无所谓,另存为R12(*dxf)格式文件. b. 打开DXP,新建PC ...
- Windows Server 2012 在个人终端上使用的推荐设置
Windows Server 2012,也就是 Windows 8 的服务器版本,相对于 Windows 8 企业版而言,增强了作为服务器的功能,弱化了作为终端系统的功能. 目前微软官方提供了 Win ...
- [算法] trie树实现
小写字母的字典树 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXN 1 ...
- Laravel Auth验证
laravel自带了auth类和User模型来帮助我们很方便的实现用户登陆.判断. 首先,先配置一下相关参数 app/config/auth.php: model 指定模型 table 指定用户表 p ...
- myeclipse设置以及快捷键
http://blog.csdn.net/anxin323/article/details/40214467 如何查看jar包里的源码和doc文档? 1. jar文件右键properties--jav ...
- [Unity]C#中 将XML和实体类之间进行相互转换的工具类
using System; using System.Xml; using System.Xml.Serialization; using System.IO; namespace LOTool { ...