【发布时间】:2016-07-01 21:08:26
【问题描述】:
我正在尝试使用这样的自定义验证注释一次应用多个常见注释:
@Retention(RetentionPolicy.RUNTIME)
@Length(max=25, min=1, message="invalid length")
@NotNull
@Pattern(regexp = "[a-zA-Z0-9]{1, 25})")
public @interface MyAnnotation {
}
并在我的模型类中使用它,如下所示:
@MyAnnotation
public String firstName;
这些验证都不起作用,但在模型类本身中使用时它们会按预期工作。我还尝试在应用程序运行方法中注册 MyAnnotation,但也没有用。
environment.jersey().register(MyAnnotation.class);
为了使用自定义验证,我还需要做什么?
【问题讨论】:
-
在这里回答了这个问题:stackoverflow.com/questions/37837497/…
标签: java validation jersey dropwizard