[英]resteasy confusion between two URL
我有2個不同的網址:
GET /stuff/{id} (where id is an Integer)
GET /stuff/foo?bar={someValue} (foo is not an Integer, it is a hard coded String)
調用/stuff/foo&bar=someValue
,出現以下錯誤:
Failed executing GET /stuff/foo&bar=someValue
...
Caused by: java.lang.NumberFormatException: For input string: "foo&bar=someValue"
代碼是:
@GET
@Path("/stuff/{id}")
public Response getById(@PathParam("id") int id) {
// code
}
@GET
@Path("/stuff/foo")
public Response foo(@QueryParam("bar") String bar) {
// code
}
我正在使用RESTEasy ,如果可能的話,我希望以這種方式保留我的URL。 顯然,RESTEasy只是嘗試在應使用foo方法的地方使用getById方法。
如何在RESTEasy中進行這項工作? (如果沒有有關RESTEasy限制的詳細說明,“更改URL”不是答案)。 我嘗試(確定)將foo代碼放在getById之前,但我遇到了相同的錯誤(當然)。
聲明的URL之間是否有任何優先級概念?
注意:我已經在另一個框架(python-flask)中實現了這種URL,並且效果很好:您只需要注意在 / stuff / {id} 之前聲明/ stuff / foo(在更多情況下先聲明特殊情況)。通用)。
編輯 :我只是犯了一個愚蠢的錯誤! 我打電話給/stuff/foo&bar=someValue
我應該打電話給/stuff/foo?bar=someValue
。 感謝@Scobal指出!
您正在呼叫GET /stuff/foo&bar=someValue
您應該調用GET /stuff/foo?bar=someValue
RESTEasy嘗試將foo&bar=someValue
解析為{id}
字段。
我無法為您提供有關RESTEasy URL優先級的答案,但是您可以這樣做:
@GET
@Path("/stuff/{id}")
public Response getById(@PathParam("id") String id, @QueryParam("bar") String bar) {
try {
int intId = Integer.parseInt(id);
// do int id things
} catch(NumberFormatException e) {
// do foo + bar things
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.