13.07.2015 Views

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

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

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

对 一 个 类 重 定 义 其 默 认 校 验 组Driver john = new Driver( "John Doe" );john.setAge( 18 );john.passedDrivingTest( true );rentalCar.setDriver( john );}assertEquals( 0, validator.validate( rentalCar, Default.class ).size() );注 意因 为 不 能 在 校 验 组 和 校 验 组 序 列 中 有 循 环 依 赖 关 系 , 所 以 , 如 果 你 想 重 定 义 一 个 类的 默 认 组 , 并 且 还 想 把 Default 组 加 入 到 这 个 重 定 义 的 序 列 当 中 的 话 , 则 不 能 简 单 的加 入 Default, 而 是 需 要 把 被 重 定 义 的 类 加 入 到 其 中 .2.3.2.2. @GroupSequenceProviderThe @javax.validation.GroupSequence annotation is a standardized Bean Validationannotation. As seen in the previous section it allows you to statically redefinethe default group sequence for a class. Hibernate Validator also offers a custom,non standardized annotation - org.hibernate.validator.group.GroupSequenceProvider - whichallows for dynamic redefinition of the default group sequence. Using the rental carscenario again, one could dynamically add the driver checks depending on whetherthe car is rented or not. 例 2.21 “RentalCar with @GroupSequenceProvider” and 例“DefaultGroupSequenceProvider implementation” show how this use-case would beimplemented.例 2.21. RentalCar with @GroupSequenceProvider@GroupSequenceProvider(RentalCarGroupSequenceProvider.class)public class RentalCar extends Car {private boolean rented;public RentalCar(String manufacturer, String licencePlate, int seatCount) {}super( manufacturer, licencePlate, seatCount );public boolean isRented() {}return rented;}public void setRented(boolean rented) {}this.rented = rented;21

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

Saved successfully!

Ooh no, something went wrong!