@NotNull @QueryParam("String") 字符串在球衣验证中不起作用
@NotNull @QueryParam("String") String not working in jersey validations
我正在尝试使用 javax.validation.validation-api 来验证 @QueryParam 参数。我是球衣新手,所以不太了解,请查看下面的代码
代码:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{services/SuperWeb}")
@ValidateOnExecution
public String getBranchName(@PathParam("name") String name,
@NotNull @QueryParam("phone") String phone,
@NotNull @QueryParam("email") String email) {
try {
//Some code where I should not check the phone and email is not null...
} catch(Exception exception) {
throw new ...
}
return "";
}
Pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
<version>2.12</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
您是否检查过以确保您没有在 class 扩展 ResourceConfig 中的 Jersey 配置中设置任何这些。
如果是,请将其设置为 false 以启用验证。试一试
还有一次通过您的 web.xml 寻求更多帮助。
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
ServerProperties.BV_FEATURE_DISABLE
我正在尝试使用 javax.validation.validation-api 来验证 @QueryParam 参数。我是球衣新手,所以不太了解,请查看下面的代码
代码:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{services/SuperWeb}")
@ValidateOnExecution
public String getBranchName(@PathParam("name") String name,
@NotNull @QueryParam("phone") String phone,
@NotNull @QueryParam("email") String email) {
try {
//Some code where I should not check the phone and email is not null...
} catch(Exception exception) {
throw new ...
}
return "";
}
Pom.xml
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-bean-validation</artifactId>
<version>2.12</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
您是否检查过以确保您没有在 class 扩展 ResourceConfig 中的 Jersey 配置中设置任何这些。 如果是,请将其设置为 false 以启用验证。试一试 还有一次通过您的 web.xml 寻求更多帮助。
CommonProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
ServerProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
ServerProperties.BV_FEATURE_DISABLE