tôi đang tìm kiếm tại @org.hibernate.validator.constaints.NotEmpty
chú thích:Chú thích lồng nhau này làm gì/cho phép?
@Documented
@Constraint(validatedBy = { })
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@ReportAsSingleViolation
@NotNull
@Size(min = 1)
public @interface NotEmpty {
String message() default "{org.hibernate.validator.constraints.NotEmpty.message}";
Class<?>[] groups() default { };
Class<? extends Payload>[] payload() default { };
/**
* Defines several {@code @NotEmpty} annotations on the same element.
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
public @interface List {
NotEmpty[] value();
}
}
Tôi đang bối rối bởi phần cuối cùng:
/**
* Defines several {@code @NotEmpty} annotations on the same element.
*/
@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
public @interface List {
NotEmpty[] value();
}
Tôi không chắc chắn làm thế nào mà làm việc, cũng không phải làm thế nào để sử dụng nó. Từ sự hiểu biết của tôi, bất cứ điều gì dưới Java 8 không cho phép lặp lại các chú thích trên cùng một phần tử.
Ai có thể làm rõ?
Nó giống như một lớp tĩnh lồng nhau hoặc giao diện lồng nhau. Sử dụng nó bằng '@ NotEmpty.List'. –