JAX-RS之@matrixParam和@PathParam
来源:互联网 发布:淘宝开店保证金怎么退 编辑:程序博客网 时间:2024/05/23 00:04
今天继续JBOSS RESETEASY学习之参数学习。今天要学习的分别是@PathParam
和@matrixParam
1)@pathparam
先看例子:
@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();
}
}
URL如下:
/users/22667788”
则匹配(@PathParam("id") String id)
所以输出:
getUserById is called, id : 22667788
2)@pathparam匹配输出多个参数:
@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();
}
}
则URl:“/users/2011/06/30”
匹配:
getUserHistory is called, year/month/day : 2011/6/30
3)matrixparam
这个主要是做分离参数的,比如:
@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
@MatrixParam("author") String author,
@MatrixParam("country") String country) {
return Response
.status(200)
.entity("getBooks is called, year : " + year
+ ", author : " + author + ", country : " + country)
.build();
}
URL:
“/books/2011/”
结果:
getBooks is called, year : 2011, author : null, country : null
URL:/books/2011;author=mkyong;country=malaysia
结果:
getBooks is called, year : 2011, author : mkyong, country : malaysia
和@matrixParam
1)@pathparam
先看例子:
@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();
}
}
URL如下:
/users/22667788”
则匹配(@PathParam("id") String id)
所以输出:
getUserById is called, id : 22667788
2)@pathparam匹配输出多个参数:
@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();
}
}
则URl:“/users/2011/06/30”
匹配:
getUserHistory is called, year/month/day : 2011/6/30
3)matrixparam
这个主要是做分离参数的,比如:
@GET
@Path("{year}")
public Response getBooks(@PathParam("year") String year,
@MatrixParam("author") String author,
@MatrixParam("country") String country) {
return Response
.status(200)
.entity("getBooks is called, year : " + year
+ ", author : " + author + ", country : " + country)
.build();
}
URL:
“/books/2011/”
结果:
getBooks is called, year : 2011, author : null, country : null
URL:/books/2011;author=mkyong;country=malaysia
结果:
getBooks is called, year : 2011, author : mkyong, country : malaysia
- JAX-RS之@matrixParam和@PathParam
- JAX-RS @MatrixParam example
- JAX-RS @PathParam example
- JAX-RS之@QueryParam和@DefaultValue
- JAX-RS之@formparam和@HeaderParam
- WebService JAX-WS和JAX-RS
- Java JAX-WS和JAX-RS webservice
- Java JAX-WS和JAX-RS webservice
- JAX-RS之上传文件
- JAX-RS之Jersey入门
- JAX-RS和spring整合
- WebService CXF-RS技术之@Pathparam与@Queryparam注解区别
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- JAX-RS
- 熟练掌握apt-cache、apt-get、dpkg、aptitude这几个关键命令
- java中thread的start()和run()的区别
- vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- 读C++ Primer 之队列类模板
- Linux下常见文件解压方法及命令
- JAX-RS之@matrixParam和@PathParam
- yaffs格式根文件系统制作
- JAX-RS之@QueryParam和@DefaultValue
- linux中apt-cache命令的用法
- JAX-RS之@formparam和@HeaderParam
- JAX-RS之下载文件
- Android学习-计算器1
- 进程地址空间地址转换为物理地址
- 免费的Bug管理系统----BugFree的安装与使用