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 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()

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章