org.springframework.util.ClassUtils#isPrimitiveOrWrapper ( )源码实例Demo

下面列出了org.springframework.util.ClassUtils#isPrimitiveOrWrapper ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Find search return type type.
 *
 * @param handlerMethod the handler method
 * @param methodResourceMapping the method resource mapping
 * @param domainType the domain type
 * @return the type
 */
private Type findSearchReturnType(HandlerMethod handlerMethod, MethodResourceMapping methodResourceMapping, Class<?> domainType) {
	Type returnType = null;
	Type returnRepoType = ReturnTypeParser.resolveType(methodResourceMapping.getMethod().getGenericReturnType(), methodResourceMapping.getMethod().getDeclaringClass());
	if (methodResourceMapping.isPagingResource()) {
		returnType = ResolvableType.forClassWithGenerics(PagedModel.class, domainType).getType();
	}
	else if (Iterable.class.isAssignableFrom(ResolvableType.forType(returnRepoType).getRawClass())) {
		returnType = ResolvableType.forClassWithGenerics(CollectionModel.class, domainType).getType();
	}
	else if (!ClassUtils.isPrimitiveOrWrapper(domainType)) {
		returnType = ResolvableType.forClassWithGenerics(EntityModel.class, domainType).getType();
	}
	if (returnType == null) {
		returnType = ReturnTypeParser.resolveType(handlerMethod.getMethod().getGenericReturnType(), handlerMethod.getBeanType());
		returnType = getType(returnType, domainType);
	}
	return returnType;
}
 
源代码2 项目: syncer   文件: SQLHelper.java
public static String inSQL(Object value) {
  if (value == null) {
    return "NULL";
  }
  Class<?> aClass = value.getClass();
  if (ClassUtils.isPrimitiveOrWrapper(aClass)
      || CharSequence.class.isAssignableFrom(aClass)
      || value instanceof Timestamp
      || value instanceof BigDecimal) {
    if (value instanceof String) {
      // TODO 2019/3/3 http://www.jguru.com/faq/view.jsp?EID=8881 {escape '/'} ?
      String replace = StringUtils.replace(StringUtils.replace(value.toString(), "'", "''"), "\\", "\\\\");
      value = "'" + replace + "'";
    } else if (value instanceof Timestamp) {
      value = "'" + value.toString() + "'";
    }
  } else if (SQLFunction.class.isAssignableFrom(aClass)) {
    value = value.toString();
  } else {
    logger.error("Unhandled complex type: {}, value: {}", aClass, value);
  }
  return value.toString();
}
 
源代码3 项目: joinfaces   文件: SpringSessionFixFilter.java
private void reSetAttributes(SessionWrapper sessionWrapper) {
	HttpSession realSession = sessionWrapper.delegate;
	Enumeration<String> attributeNames = realSession.getAttributeNames();
	while (attributeNames.hasMoreElements()) {
		String attributeName = attributeNames.nextElement();

		if (!sessionWrapper.readAttributeNames.contains(attributeName)) {
			//Attribute was not read, so we don't need to re-set it.
			continue;
		}

		Object attributeValue = realSession.getAttribute(attributeName);
		if (ClassUtils.isPrimitiveOrWrapper(attributeValue.getClass())) {
			//Attribute is primitive (immutable), so we don't need to re-set it.
			continue;
		}

		realSession.setAttribute(attributeName, attributeValue);
	}
}
 
源代码4 项目: computoser   文件: CacheKeyGenerator.java
@Override
public Object generate(Object target, Method method, Object... params) {
    StringBuilder key = new StringBuilder();
    key.append(target.getClass().getSimpleName()).append(".").append(method.getName()).append(":");

    if (params.length == 0) {
        key.append(NO_PARAM_KEY).toString();
    }

    for (Object param : params) {
        if (param == null) {
            key.append(NULL_PARAM_KEY);
        } else if (ClassUtils.isPrimitiveOrWrapper(param.getClass()) || param instanceof String) {
            key.append(param);
        } else if (param instanceof CacheKey) {
            key.append(((CacheKey) param).getCacheKey());
        } else {
            logger.warn("Using object " + param + " as cache key. Either use key='..' or implement CacheKey. Method is " + target.getClass() + "#" + method.getName());
            key.append(param.hashCode());
        }
    }

    return  key.toString();
}
 
源代码5 项目: spring-analysis-note   文件: BeanUtils.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, an enum, a String or other CharSequence, a Number, a Date,
 * a Temporal, a URI, a URL, a Locale or a Class.
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return (ClassUtils.isPrimitiveOrWrapper(clazz) ||
			Enum.class.isAssignableFrom(clazz) ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			Temporal.class.isAssignableFrom(clazz) ||
			URI.class == clazz || URL.class == clazz ||
			Locale.class == clazz || Class.class == clazz);
}
 
源代码6 项目: java-technology-stack   文件: BeanUtils.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, an enum, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class.
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return (ClassUtils.isPrimitiveOrWrapper(clazz) ||
			Enum.class.isAssignableFrom(clazz) ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			URI.class == clazz || URL.class == clazz ||
			Locale.class == clazz || Class.class == clazz);
}
 
源代码7 项目: BlogManagePlatform   文件: LegalEnumRule.java
@Override
public void check(Field field) throws CodeCheckException {
	MapEnum annotation = field.getAnnotation(MapEnum.class);
	if (annotation != null) {
		if (!ClassUtils.isPrimitiveOrWrapper(field.getType())) {
			throw new CodeCheckException(ReflectUtil.fullName(field), "不是基本类型或者其装箱类,不能使用@", MapEnum.class.getCanonicalName(), "注解");
		}
		checkLegalEnum(annotation);
	}
}
 
源代码8 项目: BlogManagePlatform   文件: LegalEnumRule.java
@Override
public void check(Method method) throws CodeCheckException {
	for (Parameter parameter : method.getParameters()) {
		MapEnum annotation = parameter.getAnnotation(MapEnum.class);
		if (annotation != null) {
			if (!ClassUtils.isPrimitiveOrWrapper(parameter.getType())) {
				throw new CodeCheckException("方法", ReflectUtil.fullName(method), "的参数", parameter.getName(), "不是基本类型或者其装箱类,不能使用@",
					MapEnum.class.getCanonicalName(), "注解");
			}
			checkLegalEnum(annotation);
		}
	}
}
 
源代码9 项目: lams   文件: BeanUtils.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class.
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			URI.class == clazz || URL.class == clazz ||
			Locale.class == clazz || Class.class == clazz);
}
 
源代码10 项目: blog_demos   文件: BeanUtils.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class.
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			clazz.equals(URI.class) || clazz.equals(URL.class) ||
			clazz.equals(Locale.class) || clazz.equals(Class.class);
}
 
源代码11 项目: spring4-understanding   文件: BeanUtils.java
/**
 * Check if the given type represents a "simple" value type:
 * a primitive, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class.
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
	return (ClassUtils.isPrimitiveOrWrapper(clazz) || clazz.isEnum() ||
			CharSequence.class.isAssignableFrom(clazz) ||
			Number.class.isAssignableFrom(clazz) ||
			Date.class.isAssignableFrom(clazz) ||
			URI.class == clazz || URL.class == clazz ||
			Locale.class == clazz || Class.class == clazz);
}