Spring常用工具类

StringUtils:(Spring 4.0+工具类)
public static boolean hasLength(CharSequence str)
public static boolean isEmpty(Object str)
public static boolean hasText(String str)
public static String replace(String inString, String oldPattern, String newPattern)
public static String delete(String inString, String pattern)
public static String capitalize(String str) //首字母大写
public static String uncapitalize(String str)  //首字母小写
public static String getFilename(String path) //文件路径截取文件名
public static String getFilenameExtension(String path)  //文件路径截取后缀

ClassUtils:(Spring 4.0+工具类)
public static Class<?> forName(String name, ClassLoader classLoader) throws ClassNotFoundException, LinkageError
public static boolean isPresent(String className, ClassLoader classLoader) 
public static Class<?> getUserClass(Class<?> clazz)  //CGLIB代理类获取父类
public static String getShortName(String className)  
public static String getShortNameAsProperty(Class<?> clazz)  //获取类名且首字母变小写
public static Method getMostSpecificMethod(Method method, Class<?> targetClass)  //如果这个方法是接口的方法,则获取实现类中实现的方法

ObjectUtils:

BeanUtils:(Spring 4.0+工具类)
public static <T> T instantiate(Class<T> clazz) throws BeanInstantiationException
public static PropertyDescriptor[] getPropertyDescriptors(Class<?> clazz) throws BeansException
public static PropertyDescriptor getPropertyDescriptor(Class<?> clazz, String propertyName) throws BeansException
public static PropertyDescriptor findPropertyForMethod(Method method) throws BeansException
public static PropertyDescriptor findPropertyForMethod(Method method, Class<?> clazz) throws BeansException
public static Class<?> findPropertyType(String propertyName, Class<?>... beanClasses)
public static boolean isSimpleProperty(Class<?> clazz)
public static boolean isSimpleValueType(Class<?> clazz)
public static void copyProperties(Object source, Object target)
public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException

AnnotatedElementUtils,

AnnotationUtils:(Spring 4.0+工具类)
public static Map<String, Object> getAnnotationAttributes(Annotation annotation)
public static Object getValue(Annotation annotation)  //获取注解上的value()值
public static Object getValue(Annotation annotation, String attributeName)
public static Object getDefaultValue(Annotation annotation) 
public static Object getDefaultValue(Annotation annotation, String attributeName)  //获取注解上的属性默认值

AnnotationAttributes: (Spring 4.0+工具类)
public AnnotationAttributes(Class<? extends Annotation> annotationType)
public AnnotationAttributes(Map<String, Object> map)
public Class<? extends Annotation> annotationType() 
public String getString(String attributeName)
public String[] getStringArray(String attributeName)
public boolean getBoolean(String attributeName)
public <N extends Number> N getNumber(String attributeName)
public <T> Class<? extends T> getClass(String attributeName)
public AnnotationAttributes getAnnotation(String attributeName)

BeanWrapperImpl: (Spring 4.0+工具类)
public BeanWrapperImpl(Object object) 
public BeanWrapperImpl(Class<?> clazz) 
public final Object getWrappedInstance()
public final Class<?> getWrappedClass() 
public void setPropertyValue(String propertyName, Object value) throws BeansException
public Class<?> getPropertyType(String propertyName) throws BeansException
public Object getPropertyValue(String propertyName)
public void setAutoGrowNestedPaths(boolean autoGrowNestedPaths) //是否自动创建属性实例
public void setPropertyValues(Map<?, ?> map) throws BeansException


FileUtils:
public static File getFile(File directory, String... names) 
public static Collection<File> listFiles( File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)  //获取目录下的文件
public static Iterator<File> iterateFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)  //遍历目录下的文件
public static Collection<File> listFiles(File directory, String[] extensions, boolean recursive)  //获取目录下的文件,可指定是否递归
public static void copyFileToDirectory(File srcFile, File destDir) throws IOException  //拷贝文件到指定目录
public static void copyFile(File srcFile, File destFile) throws IOException
public static long copyFile(File input, OutputStream output)
public static void copyInputStreamToFile(InputStream source, File destination)
public static void deleteDirectory(File directory)   //删除目录
public static void cleanDirectory(File directory)  //清空目录下文件
public static String readFileToString(File file)
public static byte[] readFileToByteArray(File file)
public static List<String> readLines(File file)
public static void writeStringToFile(File file, String data) throws IOException   //将String覆盖File内的内容
public static void writeStringToFile(File file, String data, String encoding, boolean append)   //将String追加到File内
public static void writeLines(File file, String encoding, Collection<?> lines) throws IOException 
public static void writeLines(File file, String encoding, Collection<?> lines, boolean append) 
public static void writeLines(File file, Collection<?> lines) throws IOException 

IOUtils:
public static byte[] toByteArray(InputStream input) throws IOException
public static byte[] toByteArray(Reader input) throws IOException 
public static char[] toCharArray(InputStream is) throws IOException 
public static String toString(InputStream input) throws IOException 
public static String toString(Reader input) throws IOException 
public static List<String> readLines(InputStream input) throws IOException 
public static List<String> readLines(Reader input) throws IOException 
public static InputStream toInputStream(String input) 
public static void write(byte[] data, OutputStream output)
public static void write(String data, OutputStream output) throws IOException 
public static void writeLines(Collection<?> lines, String lineEnding, OutputStream output) throws IOException 
public static int copy(InputStream input, OutputStream output)
public static int copy(Reader input, Writer output) throws IOException
public static int read(InputStream input, byte[] buffer) throws IOException
public static int read(Reader input, char[] buffer) throws IOException

Character:
public static boolean isLowerCase(char ch) 
public static boolean isUpperCase(char ch)
public static boolean isDigit(char ch) 

ReflectionUtils:(Spring 4.0+工具类)
public static void doWithLocalMethods(Class<?> clazz, MethodCallback mc) 
public static void doWithMethods(Class<?> clazz, MethodCallback mc) 
public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf) 
public static void doWithLocalFields(Class<?> clazz, FieldCallback fc) 
public static void doWithFields(Class<?> clazz, FieldCallback fc) 
public static void doWithFields(Class<?> clazz, FieldCallback fc, FieldFilter ff) 

ResolvableType:(Spring 4.0+工具类)
public static ResolvableType forClass(Class<?> clazz) 
public static ResolvableType forInstance(Object instance) 
public static ResolvableType forField(Field field) 
public static ResolvableType forConstructorParameter(Constructor<?> constructor, int parameterIndex)
public static ResolvableType forMethodReturnType(Method method) 
public static ResolvableType forMethodParameter(Method method, int parameterIndex) 
public ResolvableType asMap() 
public ResolvableType asCollection() 
public ResolvableType as(Class<?> type) 
public ResolvableType getGeneric(int... indexes)   //Map<Integer, List<String>> getGeneric(0) = Integer, getGeneric(1, 0) = String
public Class<?> resolveGeneric(int... indexes) 
public Class<?> resolve() 

Assert: (Spring 4.0+工具类)
public static void state(boolean expression, String message) 
public static void isTrue(boolean expression, String message) 
public static void isNull(Object object, String message)
public static void notNull(Object object, String message) 
public static void hasText(String text, String message) 
public static void notEmpty(Object[] array, String message)
public static void notEmpty(Collection<?> collection, String message)
public static void notEmpty(Map<?, ?> map, String message)
public static void isInstanceOf(Class<?> type, Object obj, String message)
public static void isAssignable(Class<?> superType, Class<?> subType, String message)  

Arrays:
public static <T> void sort(T[] a, Comparator<? super T> c) 
public static void fill(Object[] a, Object val) 
public static <T> List<T> asList(T... a) 
public static <T> T[] copyOf(T[] original, int newLength)

Collections:
public static <T> void sort(List<T> list, Comparator<? super T> c) 
public static <T> void fill(List<? super T> list, T obj) 
public static <T> void copy(List<? super T> dest, List<? extends T> src) 
public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) 
public static <T> List<T> unmodifiableList(List<? extends T> list)
public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends V> m)
public static <T> List<T> singletonList(T o) 
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

CollectionUtils (Spring 4.0+工具类)
public static boolean isEmpty(Collection<?> collection)
public static boolean isEmpty(Map<?, ?> map)
public static boolean containsInstance(Collection<?> collection, Object element)

MethodIntrospector: (Spring 4.0+工具类)
public static <T> Map<Method, T> selectMethods(Class<?> targetType, final MetadataLookup<T> metadataLookup)
public static Set<Method> selectMethods(Class<?> targetType, final ReflectionUtils.MethodFilter methodFilter) 
public static Method selectInvocableMethod(Method method, Class<?> targetType)

PropertyDescriptor: (Spring 4.0+工具类)
public PropertyDescriptor(String propertyName, Class<?> beanClass) throws IntrospectionException 
public synchronized Class<?> getPropertyType() 
public synchronized Method getReadMethod() 
public synchronized Method getWriteMethod() 
 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值