我想使用 Hibernate Validator,第一步我检查并研究了以下参考:
第 3 页中的第一个示例是我的问题
我云没有找到这个导入包(javax.validation.*)
在 hibernate-validator-5.0.2.Final.jar
我只找到 (org.hibernate.validator.*) 但这些类不存在
package org.hibernate.validator.referenceguide.chapter01;
import java.util.Set;
// ?????
import javax.validation.ConstraintViolation; // Not Found
import javax.validation.Validation; // Not Found
import javax.validation.Validator; // Not Found
import javax.validation.ValidatorFactory; // Not Found
// ?????
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class CarTest {
private static Validator validator;
@BeforeClass
public static void setUp() {
// ?????
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
// ?????
}
@Test
public void manufacturerIsNull() {
Car car = new Car(null, "DD-AB-123", 4);
Set<ConstraintViolation<Car>> constraintViolations
= validator.validate(car);
assertEquals(1, constraintViolations.size());
assertEquals("may not be null", constraintViolations.iterator().next().getMessage());
}
请帮助我并指导我以下代码的必要包是什么?
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();