你可能用到的Spring工具类?
现在绝大部分项目都已经拥抱Spring生态,掌握Spring常用的工具类,是非常重要,零成本增加编码效率。
一、常用工具类
- ObjectUtils
org.springframework.util.ObjectUtils
- StringUtils
org.springframework.util.StringUtils
- CollectionUtils
org.springframework.util.CollectionUtils
- BeanUtils
org.springframework.beans.BeanUtils
- Assert
org.springframework.util.Assert
- NumberUtils
org.springframework.util.NumberUtils
- ClassUtils
org.springframework.util.ClassUtils
- AnnotationUtils
org.springframework.core.annotation.AnnotationUtils
- AopUtils
org.springframework.aop.support.AopUtils
- AopContext
org.springframework.aop.framework.AopContext
- ReflectionUtils
org.springframework.util.ReflectionUtils
- FileCopyUtils
org.springframework.util.FileCopyUtils
- FileSystemUtils
org.springframework.util.FileSystemUtils
- StreamUtils
org.springframework.util.StreamUtils
- HtmlUtils
org.springframework.web.util.HtmlUtils
- TypeUtils
org.springframework.util.TypeUtils
- Base64Utils
org.springframework.util.Base64Utils
- DigestUtils
org.springframework.util.DigestUtils
- UriUtils
org.springframework.web.util.UriUtils
- ResourceUtils
org.springframework.util.ResourceUtils
- SocketUtils
org.springframework.util.SocketUtils
- AntPathMatcher
org.springframework.util.AntPathMatcher
- ParameterNameDiscoverer
org.springframework.core.ParameterNameDiscoverer
- SerializationUtils
org.springframework.util.SerializationUtils
- SystemPropertyUtils
org.springframework.util.SystemPropertyUtils
- ServletRequestUtils
org.springframework.web.bind.ServletRequestUtils
- MimeTypeUtils
org.springframework.util.MimeTypeUtils
二、工具类详情
- **ObjectUtils**
```java
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**
```java
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**
```java
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**
```java
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**
```java
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**
```java
Number NumberUtils.parseNumber(text,targetClass)
Number NumberUtils.parseNumber(text,targetClass,numberFormat)
Number NumberUtils.convertNumberToTargetClass(number,targetClass)
```
- **ClassUtils**
```java
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**
```java
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**
```java
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**
```java
Object AopContext.currentProxy()
```
- **ReflectionUtils**
```java
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**
```java
byte[] FileCopyUtils.copyToByteArray(in)
void FileCopyUtils.copy(in,out)
String FileCopyUtils.copyToString(in)
int FileCopyUtils.copy(in,out)
```
- **FileSystemUtils**
```java
boolean FileSystemUtils.deleteRecursively(root)
void FileSystemUtils.copyRecursively(src,dest)
```
- **StreamUtils**
```java
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**
```java
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**
```java
boolean TypeUtils.isAssignable(lhsType,rhsType)
boolean TypeUtils.isAssignableBound(lhsType,rhsType)
```
- **Base64Utils**
```java
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**
```java
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**
```java
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**
```java
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**
```java
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**
```java
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**
```java
String[] ParameterNameDiscoverer.getParameterNames()
```
- **SerializationUtils**
```java
Object SerializationUtils.deserialize(bytes)
byte[] SerializationUtils.serialize(object)
```
- **SystemPropertyUtils**
```java
String SystemPropertyUtils.resolvePlaceholders(text)
String SystemPropertyUtils.resolvePlaceholders(text,ignoreUnresolvablePlaceholders)
```
- **ServletRequestUtils**
```java
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**
```java
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()+"`");
}
}
你可能用到的Spring工具类?的更多相关文章
- spring 工具类大集合
接以前的文章 apache-commons 常用工具类 和文章 apache-commons 工具类扩展 小家 Spring 对 spring 的工具类做了详细的介绍(一) 这里我抽出一些好用的类,不 ...
- Spring工具类 非spring管理环境中获取bean及环境配置
SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...
- Spring工具类:WebApplicationContextUtils
当 Web 应用集成 Spring 容器后,代表 Spring 容器的WebApplicationContext对象将以 WebApplicationContext.ROOT_WEB_APPLICAT ...
- JDBC JdbTemplate&NamedParameterJdbcTemplate(Spring工具类)
使用该工具类需要从spring开发包中导入spring.jar和commons-logging.jar,这个模板是线程安全的. JdbcTemplate: public class JdbcTem ...
- spring工具类获取bean
import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebAppl ...
- 借助Spring工具类如何实现支持数据嵌套的赋值操作
假设有两个Bean A和B,想将B中的属性赋值到A实体中,可以使用get set来实现,当属性过多时,就会显得很冗余,可以使用spring提供的BeanUtils.copyProperties()来实 ...
- Spring工具类ToStringBuilder用法简介
比如说我们需要打印某个方法的User参数对象 package test; /** * * @author zhengtian * @time 2012-6-28 */ public class Use ...
- Spring工具类
文件资源访问 1.统一资源访问接口 Resource 2.实现类 FileSystemResource 通过文件系统路径访问 ClassPathResource 通过classpath路径访问 Ser ...
- 通过spring工具类获取bean
package xxx; import org.springframework.beans.BeansException; import org.springframework.beans.facto ...
随机推荐
- Not sending mail to unregistered use
其实这个问题是Jenkins管理用户的一个问题,它可以自动从git或者svn读取用户信息以及邮件(如果git等中设置了的话), 但它不又不创建Jenkins上的用户,所以你可以在pepole列表上看到 ...
- redis详解及应用(雪崩、击穿、穿透)
一. redis的简介与安装 引用:https://www.cnblogs.com/ysocean/tag/Redis%E8%AF%A6%E8%A7%A3/ 二. redis的配置文件介绍 引用:ht ...
- flutter flutter_swiper使用
flutter_swiper flutter最强大的siwiper, 多种布局方式,无限轮播,Android和IOS双端适配. 更多详情信息请移步:https://blog.csdn.net/u011 ...
- linux 代码更新-打包-重启脚本
#! /bin/sh base=/home/project/myblog cd $base git pull ] then echo "Error in git pull!!! Stop d ...
- 十二:jinja2模板中使用url_for
在页面中,有点击跳转到另一个地址的时候,可以使用url_for来指定要跳转的视图函数:{{ url_for('view_function') }} 如果该视图需要接收参数
- Multi-Object-Edit With Django FormSets
I had to write a multi-object edit table the other day for a Django project and as such I dove into ...
- 【图像处理】【计算机视觉】findContours的使用
原文地址:findContours函数参数说明及相关函数作者:鸳都学童 findContours函数,这个函数的原型为: void findContours(InputOutputArray imag ...
- websocket服务器推送 (node+express+vue+socket)
简介: 此项目需要懂一点node.express 功能: 1.前端用户登录,查看服务端推送的消息,用户只能在一个地方登录,也就是单点登录 2.服务端首先登录,上传需要推送的信息文本,后台读取文本后,存 ...
- linux 更改文件权限命令 chmod
chmod -change file mode bits :更改文件权限 chmod是用来改变文件或者目录权限的命令,但只有文件的属主和超级用户(root)才有这种权限. 更改文件权限的2种方式: 一 ...
- Linux普通用户无法使用sudo
问题描述: jenkins执行发布脚本,因为使用的是jenkins用户,所以有些shell命令需要 sudo 来执行,导致报错. + sudo rm -rf /usr/share/nginx/html ...