zoukankan      html  css  js  c++  java
  • HibernateValidators

    public final class HibernateValidators {

     

        private static final Validator VALIDATOR;

     

        private HibernateValidators() {

        }

     

        static {

            ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

            VALIDATOR = factory.getValidator();

        }

     

     

        public static <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {

            return VALIDATOR.validate(object, groups);

        }

     

        /**

         * @throws IllegalArgumentException 当校验有错误的时候抛出异常

         */

        public static <T> void throwsIfInvalid(T object, Class<?>... groups) {

            final Set<ConstraintViolation<T>> constraintViolations = validate(object, groups);

            if (!constraintViolations.isEmpty()) {

                final ImmutableMap.Builder<String, String> errorBuilder = ImmutableMap.builder();

                for (ConstraintViolation<T> violation : constraintViolations) {

                    errorBuilder.put(violation.getPropertyPath().toString(), violation.getMessage());

                }

                throw new IllegalArgumentException(errorBuilder.build().toString());

            }

        }

    }

  • 相关阅读:
    SURF与SIFT
    CVMAT操作
    flask
    爬虫
    mysql基础
    WINCE6.0_CHS_SDK安装失败
    com.microsoft.sqlserver.jdbc.SQLServerException: 通过端口 1443 连接到主机 localhost 的 TCP/IP 连接失败。
    office 2010每次打开word都要重新配置的解决方法
    如何使用Visual Studio 2008编译C语言
    Hibernate初学、遇到的问题
  • 原文地址:https://www.cnblogs.com/Struts-pring/p/10337066.html
Copyright © 2011-2022 走看看