| package com.xzx.gc.common.annotations.valid;  | 
|   | 
| import cn.hutool.core.date.DateUtil;  | 
|   | 
| import javax.validation.ConstraintValidator;  | 
| import javax.validation.ConstraintValidatorContext;  | 
|   | 
| /**  | 
|  * @author: zhongzan  | 
|  * @create: 2019-07-18 14:10  | 
|  * @description:  | 
|  */  | 
| public class DateFormatConstraintValidator implements ConstraintValidator<DateFormatConstraint, Object> {  | 
|   | 
|    private String datePattern;  | 
|   | 
|    @Override  | 
|    public void initialize(DateFormatConstraint constraintAnnotation) {  | 
|       this.datePattern=constraintAnnotation.datePattern();  | 
|    }  | 
|   | 
|    @Override  | 
|    public boolean isValid(Object obj, ConstraintValidatorContext context) {  | 
|       try {  | 
|             DateUtil.parse(obj.toString(),datePattern);  | 
|       } catch (Exception e) {  | 
|          return  false;  | 
|       }  | 
|       return true;  | 
|    }  | 
| }  |