开发者

@QueryParam regex expression

开发者 https://www.devze.com 2023-04-11 17:06 出处:网络
I am using Jerse开发者_开发技巧y for Rest and have a method that accepts @QueryParam. However, the users may send @QueryParam. like this:

I am using Jerse开发者_开发技巧y for Rest and have a method that accepts @QueryParam.

However, the users may send @QueryParam. like this:

contractName# where # is a number from 0-155.

How can I define it in QueryParam (like regex expression)?


You can't specify the regexp. However, you can define a custom Java type to represent that query param and implement your own conversion from String to that type - see http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e255 (example 2.15).


I don't think you can do it with QueryParam, but you can get the list of parameters directly:

@GET
public String get(@Context UriInfo ui) {
    MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
}

and iterate through that looking for keys that match your regular expression.


@GET
public String get (@QueryParam(value="param") String param){

 boolean test =testYourParamWithNativeRegexpTools(param);
 if( test==false)return 400;
 else //work
.....
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号