Jersey - 验证REST服务参数

问题描述 投票:1回答:1

是否有任何工具可以使用Jersey(和Maven)简单地验证查询参数?我正在尝试使用@NotNull注释(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 Bad Request。

validation rest maven jersey jax-rs
1个回答
0
投票

我的猜测是你使用的是Jersey 1.x,它不支持对PathParams或QueryParams进行带注释的验证。

请参阅Nick Telfords在https://groups.google.com/forum/#!topic/dropwizard-user/wb6iwrpSrSE的评论

© www.soinside.com 2019 - 2024. All rights reserved.