2012-05-28 25 views
0

客戶可要求兩個網址具有相同的路徑,但不同的查詢字符串:如何用不同的方法編寫球衣來匹配「/ hello」和「/ hello?name = Mike」?

1. /hello 
2. /hello?name=Mike 

如何使用的球衣來定義他們每個人的兩種不同的方法?

下面是一個例子:

@Path("/hello") 
public class HelloResource { 

    @Produces("text/plain") 
    public String justHello() {} 

    // how to call this method only the query string has "name" 
    @Produces("text/plain") 
    public String helloWithName() {} 
} 

回答

2

你不能做到這一點,新澤西州的路徑只匹配。有關全部細節,請參閱http://jersey.java.net/nonav/documentation/latest/jax-rs.html

您可以根據查詢參數存在建立自己的開關。總的來說,name = mike反正不是很RESTy。澤西島支持:

/hello/{name} 

這就是它意味着要使用的方式。

+0

這是一個小資,我的程序依賴於這個功能嚴重。 – Freewind

+0

你知道其他類似的庫支持這個功能嗎? – Freewind

+0

不是,你確定你不想嘗試使用REST來做這件事嗎?這是時髦的,所以支持更好。 – stevedbrown

相關問題