首页 > 代码库 > 空校验

空校验

    public void checkNull(final Object... args) throws ValidationException {
        for (Object arg : args) {
            if (null == arg) {
                throw new ValidationException("", ErrorMessages.DEPLOY_ARGS_NULL);// 将错误码封装在 具体的验证其里面
            }
            if (arg instanceof List) {
                int count = ((List) arg).size();
                for(int i = 0;i< count ; i++){
                    ((List) arg).remove(null);
                }
            }
            if (arg instanceof Collection && ((Collection) arg).size() == 0) {
                throw new ValidationException("", ErrorMessages.DEPLOY_ARGS_NULL);
            }
            if (arg instanceof Map && ((Map) arg).size() == 0) {
                throw new ValidationException("", ErrorMessages.DEPLOY_ARGS_NULL);
            }
        }
    }

本文出自 “11898338” 博客,谢绝转载!

空校验