<dependency> <groupId>com.github.MyCATApache</groupId> <artifactId>csv-validator</artifactId> <version>1.0.0</version> </dependency> @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface StudentValidator { String value(); } csv name,age Tom,20 Jane,25 Mike,-5 public class StudentValidatorProcessor { public static void main(String[] args) throws Exception { File csvFile = new File("student.csv"); CSVReader reader = new CSVReader(new FileReader(csvFile)); ValidatorFactory factory = new ValidatorFactory(); CSVValidator<Student> validator = factory.getValidator(Student.class); List<Student> students = validator.validate(reader); for (Student student : students) { System.out.println(student); } } } public class Student { @StudentValidator("notempty") private String name; @StudentValidator("minvalue=0") private int age; } Student{name='Tom', age=20} Student{name='Jane', age=25}


上一篇:
下一篇:
切换中文