Micronaut - 不同操作的不同验证
Micronaut - different validation for different operations
我有一个像这样的 JavaDTO:
public class myDTO {
private String name;
private Integer age;
}
我想在 Micronaut 中通过 CREATE 操作 和 UPDATE 操作[=23] 进行不同的验证 =].因此,在 Spring 中,您可以定义不同的 'groups'。请参阅此处 or here external link。所以这看起来像:
public class myDTO {
@Null(groups = OnCreate.class)
@NotNull(groups = OnUpdate.class)
private String name;
@Null(groups = OnCreate.class)
@NotNull(groups = OnUpdate.class)
private Integer age;
}
那里有类似 micronaut 的东西吗?
我认为这不是 Spring 功能,而是 javax
bean 验证器如何验证 bean。
您需要在 javax.persistence.validation.group.pre-update
适用的地方使用 Hibernate Validator。
默认的 Micronaut bean 验证没有使用 Hibernate Validator。
尝试添加 hibernate 验证器作为依赖项。
https://micronaut-projects.github.io/micronaut-hibernate-validator/latest/guide/index.html
我有一个像这样的 JavaDTO:
public class myDTO {
private String name;
private Integer age;
}
我想在 Micronaut 中通过 CREATE 操作 和 UPDATE 操作[=23] 进行不同的验证 =].因此,在 Spring 中,您可以定义不同的 'groups'。请参阅此处
public class myDTO {
@Null(groups = OnCreate.class)
@NotNull(groups = OnUpdate.class)
private String name;
@Null(groups = OnCreate.class)
@NotNull(groups = OnUpdate.class)
private Integer age;
}
那里有类似 micronaut 的东西吗?
我认为这不是 Spring 功能,而是 javax
bean 验证器如何验证 bean。
您需要在 javax.persistence.validation.group.pre-update
适用的地方使用 Hibernate Validator。
默认的 Micronaut bean 验证没有使用 Hibernate Validator。 尝试添加 hibernate 验证器作为依赖项。
https://micronaut-projects.github.io/micronaut-hibernate-validator/latest/guide/index.html