13.07.2015 Views

JSR 303 的参考实现使用指南 - JBoss

JSR 303 的参考实现使用指南 - JBoss

JSR 303 的参考实现使用指南 - JBoss

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

第 3 章 创 建 自 己 的 约 束 规 则import javax.validation.Constraint;import javax.validation.Payload;@Target( { METHOD, FIELD, ANNOTATION_TYPE })@Retention(RUNTIME)@Constraint(validatedBy = CheckCaseValidator.class)@Documentedpublic @interface CheckCase {String message() default "{com.mycompany.constraints.checkcase}";Class[] groups() default {};Class 类 型 到 空 到 数 组 .•payload 属 性 , Bean Validation API 的 使 用 者 可 以 通 过 此 属 性 来 给 约 束 条 件 指 定 严 重 级 别 . 这个 属 性 并 不 被 API 自 身 所 使 用 .提 示通 过 payload 属 性 来 指 定 默 认 错 误 严 重 级 别 的 示 例public class Severity {public static class Info extends Payload {};public static class Error extends Payload {};}public class ContactDetails {@NotNull(message="Name is mandatory", payload=Severity.Error.class)private String name;@NotNull(message="Phone number not specified, but not mandatory",payload=Severity.Info.class)private String phoneNumber;}// ...30

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!