JAX-RS @PathParam example
来源:互联网 发布:大学男生背包推荐 知乎 编辑:程序博客网 时间:2024/06/06 02:27
In JAX-RS, you can use @PathParem
to inject the value of URI parameter that defined in @Path
expression, into Java method.
1. @PathParam
– Single Parameter
A simple and normal way to use @PathParam
.
import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.core.Response;@Path("/users")public class UserRestService { @GET @Path("{id}") public Response getUserById(@PathParam("id") String id) { return Response.status(200).entity("getUserById is called, id : " + id).build(); }}
In above example, the value of {id}
from “/users/{id}
” will match to “@PathParam(“id”) String var
“.
URI Pattern : “/users/22667788
”
getUserById is called, id : 22667788
2. @PathParam
– Multiple Parameters
Example to inject multiple parameters into Java method.
import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.core.Response;@Path("/users")public class UserRestService { @GET @Path("{year}/{month}/{day}") public Response getUserHistory( @PathParam("year") int year, @PathParam("month") int month, @PathParam("day") int day) { String date = year + "/" + month + "/" + day; return Response.status(200) .entity("getUserHistory is called, year/month/day : " + date) .build(); }}
URI Pattern : “/users/2011/06/30
”
getUserHistory is called, year/month/day : 2011/6/30
0 0
- JAX-RS @PathParam example
- JAX-RS之@matrixParam和@PathParam
- JAX-RS @QueryParam example
- JAX-RS @MatrixParam example
- JAX-RS @FormParam example
- JAX-RS @Path URI matching example
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS2:JAX-RS CRUD
- JAX-WS、JAX-RS、JAXB
- JAX-WS与JAX-RS
- 解决控制器导航栏消失的问题
- scrapy爬虫之sublime Text 2在ubuntu下的安装
- 函数指针
- log 的抓取与分析
- eclipse Android 运行总是debug模式
- JAX-RS @PathParam example
- mysql删除重复数据的sql
- working copy locked
- 转:对java中int与Integer的一些理解
- 重温java基础
- 三个数排序。要求输入三个整数,按逗号隔开,把它们从小到大排列,输出结果用空格隔开。
- 嵌套类
- Python内存管理机制
- MQX中的定时器