看起来Query Param的验证无法正常工作,但Body的验证工作正常(使用@POST)
@GET
@Path("{id}")
public Foo get(@PathParam("id") Integer id,
@NotNull @QueryParam("param1") Integer param1) {
....
}
的pom.xml
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-sse</artifactId>
</dependency>
答案 0 :(得分:1)
要触发验证,请将@Valid
注释添加到参数中。
@GET
@Path("{id}")
public Foo get(@PathParam("id") Integer id,
@Valid @NotNull @QueryParam("param1") Integer param1) {
....
}