泽西岛-验证REST服务参数 [英] Jersey - validate REST service parameters
本文介绍了泽西岛-验证REST服务参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何工具可以使用Jersey(和Maven)简单地验证查询参数?我正在尝试使用@NotNull批注(jersey-bean-validation)做类似的事情:
is there any tool to simply validate query params using Jersey (and Maven)? I'm trying to do something like this using @NotNull annotation (jersey-bean-validation):
@GET
@Path("/count")
@Produces(MediaType.APPLICATION_XML)
public Response count(@NotNull @QueryParam("my_param") String my_param) {
//TODO automatically return 400 Bad Request if my_param is null
return Response.ok("This is a response", MediaType.APPLICATION_XML).build();
}
我希望该方法能够自动验证查询参数并在未提供"my_param"的情况下返回400错误请求.
I'd like the method to automatically validate query parameters and return 400 Bad Request if no "my_param" is provided.
推荐答案
我的猜测是您使用的是Jersey 1.x,它不支持针对PathParams或QueryParams的带注释的验证.
My guess is you are using Jersey 1.x, which does not support annotated validations against PathParams or QueryParams.
在 https://groups.google.com上查看Nick Telfords的评论. /forum/#!topic/dropwizard-user/wb6iwrpSrSE
这篇关于泽西岛-验证REST服务参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文