zoukankan      html  css  js  c++  java
  • 你可能用到的Spring工具类?

    现在绝大部分项目都已经拥抱Spring生态,掌握Spring常用的工具类,是非常重要,零成本增加编码效率。


    一、常用工具类

    1. ObjectUtils
      org.springframework.util.ObjectUtils
    2. StringUtils
      org.springframework.util.StringUtils
    3. CollectionUtils
      org.springframework.util.CollectionUtils
    4. BeanUtils
      org.springframework.beans.BeanUtils
    5. Assert
      org.springframework.util.Assert
    6. NumberUtils
      org.springframework.util.NumberUtils
    7. ClassUtils
      org.springframework.util.ClassUtils
    8. AnnotationUtils
      org.springframework.core.annotation.AnnotationUtils
    9. AopUtils
      org.springframework.aop.support.AopUtils
    10. AopContext
      org.springframework.aop.framework.AopContext
    11. ReflectionUtils
      org.springframework.util.ReflectionUtils
    12. FileCopyUtils
      org.springframework.util.FileCopyUtils
    13. FileSystemUtils
      org.springframework.util.FileSystemUtils
    14. StreamUtils
      org.springframework.util.StreamUtils
    15. HtmlUtils
      org.springframework.web.util.HtmlUtils
    16. TypeUtils
      org.springframework.util.TypeUtils
    17. Base64Utils
      org.springframework.util.Base64Utils
    18. DigestUtils
      org.springframework.util.DigestUtils
    19. UriUtils
      org.springframework.web.util.UriUtils
    20. ResourceUtils
      org.springframework.util.ResourceUtils
    21. SocketUtils
      org.springframework.util.SocketUtils
    22. AntPathMatcher
      org.springframework.util.AntPathMatcher
    23. ParameterNameDiscoverer
      org.springframework.core.ParameterNameDiscoverer
    24. SerializationUtils
      org.springframework.util.SerializationUtils
    25. SystemPropertyUtils
      org.springframework.util.SystemPropertyUtils
    26. ServletRequestUtils
      org.springframework.web.bind.ServletRequestUtils
    27. MimeTypeUtils
      org.springframework.util.MimeTypeUtils
    28. ResolvableType (泛型工具)
      org.springframework.core.ResolvableType

    二、工具类详情


    • ObjectUtils
    int ObjectUtils.nullSafeHashCode(obj)
    boolean ObjectUtils.isCheckedException(ex)
    boolean ObjectUtils.containsConstant(enumValues,constant,caseSensitive)
    boolean ObjectUtils.isCompatibleWithThrowsClause(ex,declaredExceptions)
    int ObjectUtils.nullSafeHashCode(array)
    String ObjectUtils.getIdentityHexString(obj)
    String ObjectUtils.getDisplayString(obj)
    String ObjectUtils.nullSafeToString(obj)
    String ObjectUtils.identityToString(obj)
    Object ObjectUtils.unwrapOptional(obj)
    boolean ObjectUtils.containsElement(array,element)
    Object[] ObjectUtils.toObjectArray(source)
    boolean ObjectUtils.isEmpty(obj)
    String ObjectUtils.nullSafeClassName(obj)
    boolean ObjectUtils.containsConstant(enumValues,constant)
    boolean ObjectUtils.nullSafeEquals(o1,o2)
    int ObjectUtils.hashCode(lng)
    int ObjectUtils.hashCode(bool)
    Object[] ObjectUtils.addObjectToArray(array,obj)
    boolean ObjectUtils.isEmpty(array)
    boolean ObjectUtils.isArray(obj)
    int ObjectUtils.hashCode(flt)
    Enum ObjectUtils.caseInsensitiveValueOf(enumValues,constant)
    String ObjectUtils.nullSafeToString(array)
    int ObjectUtils.hashCode(dbl)
    

    • StringUtils
    String StringUtils.collectionToDelimitedString(coll,delim,prefix,suffix)
    boolean StringUtils.substringMatch(str,index,substring)
    String[] StringUtils.addStringToArray(array,str)
    boolean StringUtils.hasText(str)
    String StringUtils.getFilename(path)
    String StringUtils.uriDecode(source,charset)
    String StringUtils.uncapitalize(str)
    String StringUtils.trimWhitespace(str)
    Properties StringUtils.splitArrayElementsIntoProperties(array,delimiter)
    String StringUtils.toLanguageTag(locale)
    String[] StringUtils.toStringArray(enumeration)
    String[] StringUtils.tokenizeToStringArray(str,delimiters)
    boolean StringUtils.pathEquals(path1,path2)
    String StringUtils.collectionToCommaDelimitedString(coll)
    TimeZone StringUtils.parseTimeZoneString(timeZoneString)
    String[] StringUtils.tokenizeToStringArray(str,delimiters,trimTokens,ignoreEmptyTokens)
    String[] StringUtils.commaDelimitedListToStringArray(str)
    boolean StringUtils.startsWithIgnoreCase(str,prefix)
    String StringUtils.getFilenameExtension(path)
    Properties StringUtils.splitArrayElementsIntoProperties(array,delimiter,charsToDelete)
    String StringUtils.capitalize(str)
    int StringUtils.countOccurrencesOf(str,sub)
    boolean StringUtils.isEmpty(str)
    String StringUtils.trimLeadingWhitespace(str)
    String[] StringUtils.delimitedListToStringArray(str,delimiter)
    String[] StringUtils.sortStringArray(array)
    String[] StringUtils.toStringArray(collection)
    String StringUtils.trimTrailingCharacter(str,trailingCharacter)
    String StringUtils.quote(str)
    Object StringUtils.quoteIfString(obj)
    String[] StringUtils.concatenateStringArrays(array1,array2)
    String StringUtils.arrayToDelimitedString(arr,delim)
    String[] StringUtils.split(toSplit,delimiter)
    String[] StringUtils.mergeStringArrays(array1,array2)
    String StringUtils.replace(inString,oldPattern,newPattern)
    String StringUtils.delete(inString,pattern)
    boolean StringUtils.endsWithIgnoreCase(str,suffix)
    Locale StringUtils.parseLocale(localeValue)
    String StringUtils.trimLeadingCharacter(str,leadingCharacter)
    String StringUtils.deleteAny(inString,charsToDelete)
    boolean StringUtils.hasLength(str)
    String[] StringUtils.trimArrayElements(array)
    Set StringUtils.commaDelimitedListToSet(str)
    String StringUtils.stripFilenameExtension(path)
    String[] StringUtils.delimitedListToStringArray(str,delimiter,charsToDelete)
    String StringUtils.trimAllWhitespace(str)
    String[] StringUtils.removeDuplicateStrings(array)
    String StringUtils.cleanPath(path)
    String StringUtils.collectionToDelimitedString(coll,delim)
    Locale StringUtils.parseLocaleString(localeString)
    boolean StringUtils.containsWhitespace(str)
    String StringUtils.unqualify(qualifiedName,separator)
    String StringUtils.unqualify(qualifiedName)
    String StringUtils.arrayToCommaDelimitedString(arr)
    String StringUtils.applyRelativePath(path,relativePath)
    String StringUtils.trimTrailingWhitespace(str)
    

    • CollectionUtils
    void CollectionUtils.mergePropertiesIntoMap(props,map)
    MultiValueMap CollectionUtils.unmodifiableMultiValueMap(map)
    Object[] CollectionUtils.toArray(enumeration,array)
    boolean CollectionUtils.isEmpty(collection)
    boolean CollectionUtils.contains(iterator,element)
    Object CollectionUtils.lastElement(set)
    void CollectionUtils.mergeArrayIntoCollection(array,collection)
    boolean CollectionUtils.isEmpty(map)
    Object CollectionUtils.lastElement(list)
    Object CollectionUtils.findValueOfType(collection,types)
    MultiValueMap CollectionUtils.toMultiValueMap(map)
    boolean CollectionUtils.containsAny(source,candidates)
    Object CollectionUtils.findValueOfType(collection,type)
    List CollectionUtils.arrayToList(source)
    boolean CollectionUtils.contains(enumeration,element)
    Object CollectionUtils.findFirstMatch(source,candidates)
    boolean CollectionUtils.hasUniqueObject(collection)
    Iterator CollectionUtils.toIterator(enumeration)
    Class CollectionUtils.findCommonElementType(collection)
    boolean CollectionUtils.containsInstance(collection,element)
    

    • BeanUtils
    PropertyDescriptor BeanUtils.getPropertyDescriptor(clazz,propertyName)
    Constructor BeanUtils.findPrimaryConstructor(clazz)
    Method BeanUtils.resolveSignature(signature,clazz)
    Method BeanUtils.findMethodWithMinimalParameters(clazz,methodName)
    Class BeanUtils.findPropertyType(propertyName,beanClasses)
    Method BeanUtils.findMethod(clazz,methodName,paramTypes)
    void BeanUtils.copyProperties(source,target,ignoreProperties)
    MethodParameter BeanUtils.getWriteMethodParameter(pd)
    Method BeanUtils.findDeclaredMethod(clazz,methodName,paramTypes)
    boolean BeanUtils.isSimpleProperty(type)
    PropertyEditor BeanUtils.findEditorByConvention(targetType)
    boolean BeanUtils.isSimpleValueType(type)
    Object BeanUtils.instantiate(clazz)
    Method BeanUtils.findMethodWithMinimalParameters(methods,methodName)
    Object BeanUtils.instantiateClass(clazz)
    void BeanUtils.copyProperties(source,target)
    Method BeanUtils.findDeclaredMethodWithMinimalParameters(clazz,methodName)
    PropertyDescriptor BeanUtils.findPropertyForMethod(method,clazz)
    PropertyDescriptor BeanUtils.findPropertyForMethod(method)
    void BeanUtils.copyProperties(source,target,editable)
    PropertyDescriptor[] BeanUtils.getPropertyDescriptors(clazz)
    Object BeanUtils.instantiateClass(clazz,assignableTo)
    Object BeanUtils.instantiateClass(ctor,args)
    

    • Assert
    void Assert.isInstanceOf(type,obj,messageSupplier)
    void Assert.notEmpty(collection)
    void Assert.hasText(text,message)
    void Assert.doesNotContain(textToSearch,substring)
    void Assert.notEmpty(collection,messageSupplier)
    void Assert.notNull(object,messageSupplier)
    void Assert.isInstanceOf(type,obj,message)
    void Assert.notEmpty(array,messageSupplier)
    void Assert.noNullElements(array,message)
    void Assert.state(expression)
    void Assert.hasText(text,messageSupplier)
    void Assert.isNull(object)
    void Assert.isTrue(expression,message)
    void Assert.doesNotContain(textToSearch,substring,messageSupplier)
    void Assert.notEmpty(map,message)
    void Assert.notEmpty(map)
    void Assert.hasLength(text,message)
    void Assert.state(expression,messageSupplier)
    void Assert.isInstanceOf(type,obj)
    void Assert.notNull(object,message)
    void Assert.isTrue(expression,messageSupplier)
    void Assert.isTrue(expression)
    void Assert.isAssignable(superType,subType,message)
    void Assert.notNull(object)
    void Assert.isNull(object,messageSupplier)
    void Assert.noNullElements(array,messageSupplier)
    void Assert.doesNotContain(textToSearch,substring,message)
    void Assert.notEmpty(array,message)
    void Assert.isNull(object,message)
    void Assert.notEmpty(array)
    void Assert.hasLength(text,messageSupplier)
    void Assert.notEmpty(collection,message)
    void Assert.isAssignable(superType,subType)
    void Assert.noNullElements(array)
    void Assert.hasLength(text)
    void Assert.state(expression,message)
    void Assert.isAssignable(superType,subType,messageSupplier)
    void Assert.notEmpty(map,messageSupplier)
    void Assert.hasText(text)
    

    • NumberUtils
    Number NumberUtils.parseNumber(text,targetClass)
    Number NumberUtils.parseNumber(text,targetClass,numberFormat)
    Number NumberUtils.convertNumberToTargetClass(number,targetClass)
    

    • ClassUtils
    boolean ClassUtils.isPrimitiveWrapperArray(clazz)
    Class ClassUtils.createCompositeInterface(interfaces,classLoader)
    String ClassUtils.getQualifiedMethodName(method,clazz)
    boolean ClassUtils.isCglibProxyClass(clazz)
    boolean ClassUtils.matchesTypeName(clazz,typeName)
    Class[] ClassUtils.getAllInterfacesForClass(clazz,classLoader)
    String ClassUtils.getPackageName(fqClassName)
    Class ClassUtils.getUserClass(instance)
    String ClassUtils.getShortNameAsProperty(clazz)
    Class ClassUtils.resolvePrimitiveClassName(name)
    boolean ClassUtils.hasConstructor(clazz,paramTypes)
    Set ClassUtils.getAllInterfacesForClassAsSet(clazz)
    boolean ClassUtils.isInnerClass(clazz)
    Class ClassUtils.determineCommonAncestor(clazz1,clazz2)
    int ClassUtils.getMethodCountForName(clazz,methodName)
    Method ClassUtils.getMethod(clazz,methodName,paramTypes)
    ClassLoader ClassUtils.getDefaultClassLoader()
    Set ClassUtils.getAllInterfacesForClassAsSet(clazz,classLoader)
    boolean ClassUtils.hasAtLeastOneMethodWithName(clazz,methodName)
    boolean ClassUtils.isAssignableValue(type,value)
    boolean ClassUtils.isJavaLanguageInterface(ifc)
    boolean ClassUtils.isPrimitiveArray(clazz)
    boolean ClassUtils.isCacheSafe(clazz,classLoader)
    String ClassUtils.classPackageAsResourcePath(clazz)
    Class ClassUtils.getUserClass(clazz)
    String ClassUtils.classNamesToString(classes)
    String ClassUtils.getDescriptiveType(value)
    Class ClassUtils.resolveClassName(className,classLoader)
    Class[] ClassUtils.toClassArray(collection)
    Class[] ClassUtils.getAllInterfacesForClass(clazz)
    Class ClassUtils.resolvePrimitiveIfNecessary(clazz)
    String ClassUtils.getShortName(clazz)
    String ClassUtils.addResourcePathToPackagePath(clazz,resourceName)
    Set ClassUtils.getAllInterfacesAsSet(instance)
    Constructor ClassUtils.getConstructorIfAvailable(clazz,paramTypes)
    boolean ClassUtils.hasMethod(clazz,methodName,paramTypes)
    String ClassUtils.convertClassNameToResourcePath(className)
    boolean ClassUtils.isPrimitiveOrWrapper(clazz)
    boolean ClassUtils.isPresent(className,classLoader)
    boolean ClassUtils.isCglibProxyClassName(className)
    boolean ClassUtils.isCglibProxy(object)
    String ClassUtils.getQualifiedName(clazz)
    String ClassUtils.getShortName(className)
    Method ClassUtils.getInterfaceMethodIfPossible(method)
    boolean ClassUtils.isUserLevelMethod(method)
    Method ClassUtils.getMostSpecificMethod(method,targetClass)
    String ClassUtils.convertResourcePathToClassName(resourcePath)
    ClassLoader ClassUtils.overrideThreadContextClassLoader(classLoaderToUse)
    Method ClassUtils.getMethodIfAvailable(clazz,methodName,paramTypes)
    String ClassUtils.getPackageName(clazz)
    Class[] ClassUtils.getAllInterfaces(instance)
    boolean ClassUtils.isVisible(clazz,classLoader)
    String ClassUtils.getClassFileName(clazz)
    boolean ClassUtils.isAssignable(lhsType,rhsType)
    Class ClassUtils.forName(name,classLoader)
    boolean ClassUtils.isPrimitiveWrapper(clazz)
    Method ClassUtils.getStaticMethod(clazz,methodName,args)
    String ClassUtils.getQualifiedMethodName(method)
    

    • AnnotationUtils
    Annotation AnnotationUtils.synthesizeAnnotation(annotation,annotatedElement)
    Annotation AnnotationUtils.getAnnotation(annotation,annotationType)
    Set AnnotationUtils.getDeclaredRepeatableAnnotations(annotatedElement,annotationType)
    boolean AnnotationUtils.isInJavaLangAnnotationPackage(annotation)
    Object AnnotationUtils.getDefaultValue(annotationType)
    void AnnotationUtils.postProcessAnnotationAttributes(annotatedElement,attributes,classValuesAsString)
    Annotation AnnotationUtils.synthesizeAnnotation(annotationType)
    Set AnnotationUtils.getRepeatableAnnotations(annotatedElement,annotationType)
    AnnotationAttributes AnnotationUtils.getAnnotationAttributes(annotatedElement,annotation,classValuesAsString,nestedAnnotationsAsMap)
    Annotation AnnotationUtils.getAnnotation(annotatedElement,annotationType)
    Annotation AnnotationUtils.findAnnotation(clazz,annotationType)
    Map AnnotationUtils.getAnnotationAttributes(annotation)
    void AnnotationUtils.registerDefaultValues(attributes)
    Map AnnotationUtils.getAnnotationAttributes(annotation,classValuesAsString)
    Object AnnotationUtils.getValue(annotation,attributeName)
    Set AnnotationUtils.getDeclaredRepeatableAnnotations(annotatedElement,annotationType,containerAnnotationType)
    Object AnnotationUtils.getDefaultValue(annotation)
    boolean AnnotationUtils.isInJavaLangAnnotationPackage(annotationType)
    boolean AnnotationUtils.isAnnotationDeclaredLocally(annotationType,clazz)
    Annotation[] AnnotationUtils.getAnnotations(method)
    Annotation AnnotationUtils.findAnnotation(annotatedElement,annotationType)
    Object AnnotationUtils.getValue(annotation)
    void AnnotationUtils.validateAnnotation(annotation)
    Annotation[] AnnotationUtils.getAnnotations(annotatedElement)
    AnnotationAttributes AnnotationUtils.getAnnotationAttributes(annotatedElement,annotation)
    boolean AnnotationUtils.isAnnotationInherited(annotationType,clazz)
    boolean AnnotationUtils.isAnnotationMetaPresent(annotationType,metaAnnotationType)
    Annotation AnnotationUtils.synthesizeAnnotation(attributes,annotationType,annotatedElement)
    Set AnnotationUtils.getRepeatableAnnotations(annotatedElement,annotationType,containerAnnotationType)
    void AnnotationUtils.clearCache()
    AnnotationAttributes AnnotationUtils.getAnnotationAttributes(annotation,classValuesAsString,nestedAnnotationsAsMap)
    Class AnnotationUtils.findAnnotationDeclaringClass(annotationType,clazz)
    Class AnnotationUtils.findAnnotationDeclaringClassForTypes(annotationTypes,clazz)
    Object AnnotationUtils.getDefaultValue(annotationType,attributeName)
    Object AnnotationUtils.getDefaultValue(annotation,attributeName)
    Annotation AnnotationUtils.getAnnotation(method,annotationType)
    Annotation AnnotationUtils.findAnnotation(method,annotationType)
    

    • AopUtils
    List AopUtils.findAdvisorsThatCanApply(candidateAdvisors,clazz)
    Class AopUtils.getTargetClass(candidate)
    boolean AopUtils.canApply(pc,targetClass)
    boolean AopUtils.canApply(advisor,targetClass)
    boolean AopUtils.isAopProxy(object)
    boolean AopUtils.canApply(pc,targetClass,hasIntroductions)
    Object AopUtils.invokeJoinpointUsingReflection(target,method,args)
    Method AopUtils.selectInvocableMethod(method,targetType)
    Method AopUtils.getMostSpecificMethod(method,targetClass)
    boolean AopUtils.isToStringMethod(method)
    boolean AopUtils.isJdkDynamicProxy(object)
    boolean AopUtils.isEqualsMethod(method)
    boolean AopUtils.isCglibProxy(object)
    boolean AopUtils.isHashCodeMethod(method)
    boolean AopUtils.isFinalizeMethod(method)
    boolean AopUtils.canApply(advisor,targetClass,hasIntroductions)
    

    • AopContext
    Object AopContext.currentProxy()
    

    • ReflectionUtils
    void ReflectionUtils.makeAccessible(method)
    void ReflectionUtils.makeAccessible(ctor)
    Method[] ReflectionUtils.getUniqueDeclaredMethods(leafClass)
    Object ReflectionUtils.invokeMethod(method,target)
    Method ReflectionUtils.findMethod(clazz,name)
    boolean ReflectionUtils.isEqualsMethod(method)
    void ReflectionUtils.rethrowRuntimeException(ex)
    boolean ReflectionUtils.isObjectMethod(method)
    void ReflectionUtils.handleInvocationTargetException(ex)
    boolean ReflectionUtils.isCglibRenamedMethod(renamedMethod)
    boolean ReflectionUtils.isToStringMethod(method)
    boolean ReflectionUtils.declaresException(method,exceptionType)
    void ReflectionUtils.shallowCopyFieldState(src,dest)
    void ReflectionUtils.doWithMethods(clazz,mc,mf)
    Object ReflectionUtils.invokeMethod(method,target,args)
    void ReflectionUtils.makeAccessible(field)
    Field ReflectionUtils.findField(clazz,name)
    Object ReflectionUtils.invokeJdbcMethod(method,target,args)
    void ReflectionUtils.rethrowException(ex)
    Method[] ReflectionUtils.getAllDeclaredMethods(leafClass)
    void ReflectionUtils.doWithLocalMethods(clazz,mc)
    Object ReflectionUtils.getField(field,target)
    Method ReflectionUtils.findMethod(clazz,name,paramTypes)
    void ReflectionUtils.doWithMethods(clazz,mc)
    void ReflectionUtils.doWithLocalFields(clazz,fc)
    void ReflectionUtils.doWithFields(clazz,fc)
    void ReflectionUtils.doWithFields(clazz,fc,ff)
    Constructor ReflectionUtils.accessibleConstructor(clazz,parameterTypes)
    void ReflectionUtils.clearCache()
    boolean ReflectionUtils.isHashCodeMethod(method)
    boolean ReflectionUtils.isPublicStaticFinal(field)
    void ReflectionUtils.setField(field,target,value)
    void ReflectionUtils.handleReflectionException(ex)
    Object ReflectionUtils.invokeJdbcMethod(method,target)
    Field ReflectionUtils.findField(clazz,name,type)
    

    • FileCopyUtils
    byte[] FileCopyUtils.copyToByteArray(in)
    void FileCopyUtils.copy(in,out)
    String FileCopyUtils.copyToString(in)
    int FileCopyUtils.copy(in,out)
    

    • FileSystemUtils
    boolean FileSystemUtils.deleteRecursively(root)
    void FileSystemUtils.copyRecursively(src,dest)
    

    • StreamUtils
    void StreamUtils.copy(in,charset,out)
    int StreamUtils.drain(in)
    InputStream StreamUtils.nonClosing(in)
    OutputStream StreamUtils.nonClosing(out)
    long StreamUtils.copyRange(in,out,start,end)
    String StreamUtils.copyToString(in,charset)
    int StreamUtils.copy(in,out)
    byte[] StreamUtils.copyToByteArray(in)
    void StreamUtils.copy(in,out)
    InputStream StreamUtils.emptyInput()
    

    • HtmlUtils
    String HtmlUtils.htmlEscapeHex(input,encoding)
    String HtmlUtils.htmlUnescape(input)
    String HtmlUtils.htmlEscapeHex(input)
    String HtmlUtils.htmlEscapeDecimal(input,encoding)
    String HtmlUtils.htmlEscape(input,encoding)
    String HtmlUtils.htmlEscapeDecimal(input)
    String HtmlUtils.htmlEscape(input)
    

    • TypeUtils
    boolean TypeUtils.isAssignable(lhsType,rhsType)
    boolean TypeUtils.isAssignableBound(lhsType,rhsType)
    

    • Base64Utils
    byte[] Base64Utils.decodeUrlSafe(src)
    String Base64Utils.encodeToString(src)
    byte[] Base64Utils.encode(src)
    byte[] Base64Utils.encodeUrlSafe(src)
    byte[] Base64Utils.decodeFromString(src)
    byte[] Base64Utils.decode(src)
    byte[] Base64Utils.decodeFromUrlSafeString(src)
    String Base64Utils.encodeToUrlSafeString(src)
    

    • DigestUtils
    String DigestUtils.md5DigestAsHex(bytes)
    StringBuilder DigestUtils.appendMd5DigestAsHex(bytes,builder)
    byte[] DigestUtils.md5Digest(bytes)
    StringBuilder DigestUtils.appendMd5DigestAsHex(inputStream,builder)
    byte[] DigestUtils.md5Digest(inputStream)
    String DigestUtils.md5DigestAsHex(inputStream)
    

    • UriUtils
    String UriUtils.encode(source,charset)
    String UriUtils.encodeAuthority(authority,charset)
    String UriUtils.encodeQueryParam(queryParam,charset)
    String UriUtils.encodeQuery(query,charset)
    String UriUtils.encodeUserInfo(userInfo,encoding)
    String UriUtils.encodePort(port,charset)
    String UriUtils.encode(source,encoding)
    String UriUtils.encodePathSegment(segment,charset)
    String UriUtils.encodeUserInfo(userInfo,charset)
    String UriUtils.encodeQuery(query,encoding)
    String UriUtils.extractFileExtension(path)
    String UriUtils.decode(source,charset)
    String UriUtils.encodeHost(host,charset)
    String UriUtils.encodeAuthority(authority,encoding)
    String UriUtils.encodePath(path,charset)
    String UriUtils.encodeHost(host,encoding)
    String UriUtils.decode(source,encoding)
    String UriUtils.encodeScheme(scheme,encoding)
    String UriUtils.encodePathSegment(segment,encoding)
    String UriUtils.encodeFragment(fragment,encoding)
    String UriUtils.encodePort(port,encoding)
    String UriUtils.encodePath(path,encoding)
    String UriUtils.encodeScheme(scheme,charset)
    Map UriUtils.encodeUriVariables(uriVariables)
    String UriUtils.encodeFragment(fragment,charset)
    String UriUtils.encodeQueryParam(queryParam,encoding)
    Object[] UriUtils.encodeUriVariables(uriVariables)
    

    • ResourceUtils
    URL ResourceUtils.extractArchiveURL(jarUrl)
    void ResourceUtils.useCachesIfNecessary(con)
    File ResourceUtils.getFile(resourceUri)
    URI ResourceUtils.toURI(location)
    URL ResourceUtils.extractJarFileURL(jarUrl)
    boolean ResourceUtils.isJarURL(url)
    boolean ResourceUtils.isFileURL(url)
    File ResourceUtils.getFile(resourceUrl,description)
    boolean ResourceUtils.isJarFileURL(url)
    File ResourceUtils.getFile(resourceUri,description)
    File ResourceUtils.getFile(resourceLocation)
    URL ResourceUtils.getURL(resourceLocation)
    File ResourceUtils.getFile(resourceUrl)
    boolean ResourceUtils.isUrl(resourceLocation)
    URI ResourceUtils.toURI(url)
    

    • SocketUtils
    int SocketUtils.findAvailableUdpPort(minPort,maxPort)
    SortedSet SocketUtils.findAvailableTcpPorts(numRequested,minPort,maxPort)
    int SocketUtils.findAvailableTcpPort(minPort)
    int SocketUtils.findAvailableUdpPort()
    SortedSet SocketUtils.findAvailableTcpPorts(numRequested)
    int SocketUtils.findAvailableUdpPort(minPort)
    SortedSet SocketUtils.findAvailableUdpPorts(numRequested)
    SortedSet SocketUtils.findAvailableUdpPorts(numRequested,minPort,maxPort)
    int SocketUtils.findAvailableTcpPort()
    int SocketUtils.findAvailableTcpPort(minPort,maxPort)
    

    • AntPathMatcher
    void AntPathMatcher.setPathSeparator(pathSeparator)
    String AntPathMatcher.combine(pattern1,pattern2)
    boolean AntPathMatcher.isPattern(path)
    void AntPathMatcher.setCachePatterns(cachePatterns)
    void AntPathMatcher.setTrimTokens(trimTokens)
    void AntPathMatcher.setCaseSensitive(caseSensitive)
    Map AntPathMatcher.extractUriTemplateVariables(pattern,path)
    boolean AntPathMatcher.matchStart(pattern,path)
    boolean AntPathMatcher.match(pattern,path)
    String AntPathMatcher.extractPathWithinPattern(pattern,path)
    Comparator AntPathMatcher.getPatternComparator(path)
    

    • ParameterNameDiscoverer
    String[] ParameterNameDiscoverer.getParameterNames()
    

    • SerializationUtils
    Object SerializationUtils.deserialize(bytes)
    byte[] SerializationUtils.serialize(object)
    

    • SystemPropertyUtils
    String SystemPropertyUtils.resolvePlaceholders(text)
    String SystemPropertyUtils.resolvePlaceholders(text,ignoreUnresolvablePlaceholders)
    

    • ServletRequestUtils
    String ServletRequestUtils.getStringParameter(request,name)
    String[] ServletRequestUtils.getStringParameters(request,name)
    long ServletRequestUtils.getRequiredLongParameter(request,name)
    int[] ServletRequestUtils.getIntParameters(request,name)
    long[] ServletRequestUtils.getRequiredLongParameters(request,name)
    float ServletRequestUtils.getRequiredFloatParameter(request,name)
    double[] ServletRequestUtils.getDoubleParameters(request,name)
    String ServletRequestUtils.getStringParameter(request,name,defaultVal)
    Integer ServletRequestUtils.getIntParameter(request,name)
    Double ServletRequestUtils.getDoubleParameter(request,name)
    double ServletRequestUtils.getDoubleParameter(request,name,defaultVal)
    long[] ServletRequestUtils.getLongParameters(request,name)
    double ServletRequestUtils.getRequiredDoubleParameter(request,name)
    boolean[] ServletRequestUtils.getRequiredBooleanParameters(request,name)
    float[] ServletRequestUtils.getFloatParameters(request,name)
    Boolean ServletRequestUtils.getBooleanParameter(request,name)
    Float ServletRequestUtils.getFloatParameter(request,name)
    double[] ServletRequestUtils.getRequiredDoubleParameters(request,name)
    int ServletRequestUtils.getRequiredIntParameter(request,name)
    float[] ServletRequestUtils.getRequiredFloatParameters(request,name)
    float ServletRequestUtils.getFloatParameter(request,name,defaultVal)
    boolean ServletRequestUtils.getRequiredBooleanParameter(request,name)
    boolean ServletRequestUtils.getBooleanParameter(request,name,defaultVal)
    boolean[] ServletRequestUtils.getBooleanParameters(request,name)
    Long ServletRequestUtils.getLongParameter(request,name)
    String ServletRequestUtils.getRequiredStringParameter(request,name)
    int ServletRequestUtils.getIntParameter(request,name,defaultVal)
    long ServletRequestUtils.getLongParameter(request,name,defaultVal)
    String[] ServletRequestUtils.getRequiredStringParameters(request,name)
    int[] ServletRequestUtils.getRequiredIntParameters(request,name)
    

    • MimeTypeUtils
    List MimeTypeUtils.tokenize(mimeTypes)
    MimeType MimeTypeUtils.parseMimeType(mimeType)
    byte[] MimeTypeUtils.generateMultipartBoundary()
    List MimeTypeUtils.parseMimeTypes(mimeTypes)
    String MimeTypeUtils.toString(mimeTypes)
    void MimeTypeUtils.sortBySpecificity(mimeTypes)
    String MimeTypeUtils.generateMultipartBoundaryString()
    

    三、备注

    • 打印工具类方法
    /**
     * @author kancy
     * @date 2019/12/23 23:08
     **/
    public class SpringUtils {
        private static final ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer();
    
        public static void main(String[] args) {
            printClassMethod();
        }
    
        private static void printClassMethod() {
            printClassMethod(ObjectUtils.class);
            printClassMethod(StringUtils.class);
            printClassMethod(CollectionUtils.class);
            printClassMethod(BeanUtils.class);
            printClassMethod(Assert.class);
            printClassMethod(NumberUtils.class);
            printClassMethod(ClassUtils.class);
            printClassMethod(AnnotationUtils.class);
            printClassMethod(AopUtils.class);
            printClassMethod(AopContext.class);
            printClassMethod(ReflectionUtils.class);
            printClassMethod(FileCopyUtils.class);
            printClassMethod(FileSystemUtils.class);
            printClassMethod(StreamUtils.class);
            printClassMethod(HtmlUtils.class);
            printClassMethod(TypeUtils.class);
            printClassMethod(Base64Utils.class);
            printClassMethod(DigestUtils.class);
            printClassMethod(UriUtils.class);
            printClassMethod(ResourceUtils.class);
            printClassMethod(SocketUtils.class);
            printClassMethod(AntPathMatcher.class);
            printClassMethod(ParameterNameDiscoverer.class);
            printClassMethod(SerializationUtils.class);
            printClassMethod(SystemPropertyUtils.class);
            printClassMethod(ServletRequestUtils.class);
            printClassMethod(MimeTypeUtils.class);
        }
    
        private static AtomicInteger atomicInteger = new AtomicInteger(0);
        private static void printClassMethod(Class<?> utilsClass) {
            Method[] methods = utilsClass.getMethods();
            Set<String> set = new HashSet();
            Arrays.stream(methods).forEach(method -> {
                if (method.getDeclaringClass() == utilsClass){
                    String methodPath = String.format("%s %s.%s(%s)",
                            method.getReturnType().getSimpleName(),
                            method.getDeclaringClass().getSimpleName(),
                            method.getName(),
                            StringUtils.arrayToCommaDelimitedString(parameterNameDiscoverer.getParameterNames(method))
                    );
                    set.add(methodPath);
                }
            });
            System.out.println(atomicInteger.incrementAndGet()+". "+utilsClass.getSimpleName());
            System.out.println("`"+utilsClass.getName()+"`");
        }
    }
    
    
  • 相关阅读:
    MongoDB监控一 mongostat
    PHP 中 AJAX 中文乱码解决
    php常用的header头
    PHP判断访客是否移动端浏览器访问
    PHP部分字符串函数汇总
    memcached启动参数
    处理PHP中字符串的常用操作及函数
    Linux Top 命令解析
    XML的特殊字符
    Zookeeper学习(转自知乎)
  • 原文地址:https://www.cnblogs.com/kancy/p/12089025.html
Copyright © 2011-2022 走看看