gpt4 book ai didi

java - Jersey 中溢出 @QueryParams Integer

转载 作者:行者123 更新时间:2023-11-30 03:53:52 26 4
gpt4 key购买 nike

Jersey java

@GET
@Path("/path1")
public String getFunction(
@QueryParam("param1") Integer intParam1
) {
...
}

发送获取请求

  1. http://domain.cc/path1?param1=1222534625474//溢出整数

  2. http://domain.cc/path1?param1=qweqwe

如何处理这个错误?我想捕获错误并抛出另一个(我的)错误

最佳答案

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 ...
}

关于java - Jersey 中溢出 @QueryParams Integer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23740073/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com