Spring 常用工具类

2020-04-09  本文已影响0人  Harry小哥哥

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 instantiate(Class 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 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 annotationType)

public AnnotationAttributes(Map map)

public Class annotationType()

public String getString(String attributeName)

public String[] getStringArray(String attributeName)

public boolean getBoolean(String attributeName)

public N getNumber(String attributeName)

public Class 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 listFiles( File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)  //获取目录下的文件

public static Iterator iterateFiles(File directory, IOFileFilter fileFilter, IOFileFilter dirFilter)  //遍历目录下的文件

public static Collection 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 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 readLines(InputStream input) throws IOException

public static List 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> 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 void sort(T[] a, Comparator c)

public static void fill(Object[] a, Object val)

public static List asList(T... a)

public static T[] copyOf(T[] original, int newLength)

Collections:

public static void sort(List list, Comparator c)

public static void fill(List list, T obj)

public static void copy(List dest, List src)

public static Collection unmodifiableCollection(Collection c)

public static List unmodifiableList(List list)

public static Map unmodifiableMap(Map m)

public static List singletonList(T o)

public static boolean addAll(Collection 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 Map selectMethods(Class targetType, final MetadataLookup metadataLookup)

public static Set 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()

上一篇下一篇

猜你喜欢

热点阅读