All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zznote.basecommon.common.util.ValidatorUtils Maven / Gradle / Ivy

The newest version!
package com.zznote.basecommon.common.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import java.util.Set;

/**
 * Validator 校验框架工具
 *
 * @author Lion Li
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ValidatorUtils {

    private static final Validator VALID = SpringUtils.getBean(Validator.class);

    public static  void validate(T object, Class... groups) {
        Set> validate = VALID.validate(object, groups);
        if (!validate.isEmpty()) {
            throw new ConstraintViolationException("参数校验异常", validate);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy