![](/img/trans.png)
[英]Jersey 2.22: How do I retrieve the URL (with QueryParams) from WebTarget?
[英]Overflow @QueryParams Integer in Jersey
澤西島Java
@GET
@Path("/path1")
public String getFunction(
@QueryParam("param1") Integer intParam1
) {
...
}
發送獲取請求
如何處理此錯誤? 我想捕捉錯誤並拋出另一個(我的)錯誤
https://java.net/jira/browse/JERSEY-1263
@GET
public String get(@QueryParam("count") int count, @ErrorParam Map<String, String> errors) {
if (!errors.isEmpty()) {
throw new WebApplicationException(...whatever response you want to generate...);
}
... do whatever you want to do if parameters are fine ...
}
這是因為您要傳遞的號碼:
1222534625474
大於Java可以處理的最大整數值:2 ^ 31-1或2147483648。
嘗試將參數類型設置為long:
@GET
@Path("/path1")
public String getFunction(
@QueryParam("param1") Long intParam1
) {
...
}
嘗試以下方法。
@GET
@Path("/path1")
public String getFunction(
@QueryParam("param1") String intParam1Str
) {
Integer intParam1 = null;
try {
intParam1 = Integer.parseInt(intParam1Str");
} catch (Exception e) {
//do whatever you want
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.