---
title: "RESTEasy @PathParam 与正则表达式映射"
author: "flycun2"
date: "2013-06-26T11:25:53Z"
tags: ["resteasy"]
categories: ["Web前端"]
slug: "resteasy-pathparam"
draft: false
lastmod: "2013-06-26T11:25:53Z"
id: 1894573
url: "https://flycun2.iteye.com/blog/1894573"
---

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

```java

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参数值

|request|param|many
|/aaabb/some/stuff|bb|some
|/aaab/a/lot/of/stuff|b|a/lot/of


![](http://dl2.iteye.com/upload/attachment/0086/1980/ecae407b-73ca-37c9-90b4-e4b0a31a8873.png)