JSR 303 的参考实现使用指南 - JBoss
JSR 303 的参考实现使用指南 - JBoss
JSR 303 的参考实现使用指南 - JBoss
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
校 验 组 序 列首 先 我 们 创 建 一 辆 汽 车 然 后 在 没 有 明 确 指 定 使 用 哪 个 校 验 组 的 情 况 下 校 验 它 , 可 以 看 到 即 使passedVehicleInspection 的 默 认 值 是 false 也 不 会 校 验 出 错 误 来 . 因 为 定 义 在 这 个 属 性 上 的 约 束条 件 并 不 属 于 默 认 的 校 验 组 , 接 下 来 , 我 们 来 校 验 CarChecks 这 个 组 , 这 样 就 会 发 现 car 违 反 了 约 束条 件 , 必 须 让 这 个 车 先 通 过 检 测 . 接 下 来 , 我 们 给 这 个 车 增 加 一 个 司 机 , 然 后 在 基 于 DriverChecks 来校 验 , 会 发 现 因 为 这 个 司 机 因 为 还 没 有 通 过 驾 照 考 试 , 所 以 又 一 次 得 到 了 校 验 错 误 , 如 果 我 们 设置 passedDrivingTest 属 性 为 true 之 后 , DriverChecks 组 的 校 验 就 通 过 了 .最 后 , 让 我 们 再 来 校 验 所 有 的 组 中 定 义 的 约 束 条 件 , 可 以 看 到 所 有 的 约 束 条 件 都 通 过 了 验 证 .2.3.1. 校 验 组 序 列By default, constraints are evaluated in no particular order and this regardless ofwhich groups they belong to. In some situations, however, it is useful to controlthe order of the constraint evaluation. In our example from 第 2.3 节 “ 校 验 组 ” wecould for example require that first all default car constraints are passing beforewe check the road worthiness of the car. Finally before we drive away we check theactual driver constraints. In order to implement such an order one would define a newinterface and annotate it with @GroupSequence defining the order in which the groupshave to be validated.注 意如 果 这 个 校 验 组 序 列 中 有 一 个 约 束 条 件 没 有 通 过 验 证 的 话 , 那 么 此 约 束 条 件 后 面 的都 不 会 再 继 续 被 校 验 了 .例 2.17. 标 注 了 @GroupSequence 的 接 口@GroupSequence({Default.class, CarChecks.class, DriverChecks.class})public interface OrderedChecks {}警 告一 个 校 验 组 序 列 中 包 含 的 校 验 组 和 这 个 校 验 组 序 列 不 能 造 成 直 接 或 者 间 接 的 循 环引 用 . 包 括 校 验 组 继 承 . 如 果 造 成 了 循 环 引 用 的 话 , 会 导致 GroupDefinitionException 异 常 .例 2.18 “ 校 验 组 序 列 的 用 法 ” 展 示 了 校 验 组 序 列 的 用 法 .例 2.18. 校 验 组 序 列 的 用 法@Test19