RESTEasy @PathParam 与正则表达式映射

[b]不翻译了@PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.[/b]


package com.example.rest.resteasy.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloWorldRestService {
@GET
@Path("{var:.*}/stuff")
public Response getStuff(@PathParam("var") String var) {
String result = "RESTEasy getStuff() is called! pathParam=" + var;
return Response.status(200).entity(result).build();
}

@GET
@Path("/aaa{param:b+}/{many:.*}/stuff")
public Response getIt(@PathParam("param") String bs, @PathParam("many") String many) {
String result = "RESTEasy getIt() is called! pathParam=[param:" + bs + ",many=" + many + "]";
return Response.status(200).entity(result).build();
}
}


通过下面的请求,让我们看到参数“param”与参数"many" 对应的@PathParam参数值
[table]
|request|param|many
|/aaabb/some/stuff|bb|some
|/aaab/a/lot/of/stuff|b|a/lot/of
[/table]

[img]http://dl2.iteye.com/upload/attachment/0086/1980/ecae407b-73ca-37c9-90b4-e4b0a31a8873.png[/img]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值