Spring全家桶中几个有用的儿子
大家好,我是中恒,今天给大家整理spring开发中比较常用的工具,废话不多说,直接上干货。字符串处理工具:StringUtils// 判断字符串是否为空 public static boolean isEmpty(@Nullable Object str) // 去掉所有空格 public static String trimAllWhitespace(String str) // 删除给定字符中的任何字符 public static String deleteAny(String inString, @Nullable String charsToDelete) // 获取文件的扩展名 public static String getFilenameExtension(@Nullable String path) // 替换给定字符串 public static String replace(String inString, String oldPattern, @Nullable String newPattern) ......集合工具类:CollectionUtils// 判断集合是否为空 public static boolean isEmpty(@Nullable Collection<?> collection) // 把给定的propertie属性合并到给定map public static void mergePropertiesIntoMap(@Nullable Properties props, Map map) // 检查给定的枚举是否包含给定的元素。 public static boolean contains(@Nullable Enumeration<?> enumeration, Object element) // 枚举转集合 public static A[] toArray(Enumeration enumeration, A[] array) ......Web相关处理工具:WebUtils// 获取cookie public static Cookie getCookie(HttpServletRequest request, String name) // 返回当前web应用程序的临时目录(由servlet容器提供) public static File getTempDir(ServletContext servletContext) // 根据url读取文件名 WebUtils.extractFullFilenameFromUrlPath("sdf/sadfa/asdfasdf.pdf") // 获取session属性信息 public static Object getSessionAttribute(HttpServletRequest request, String name) ......属性相关工具:PropertiesLoaderUtils// 从给定的EncodedResource加载属性,可能定义属性文件的特定编码。 public static Properties loadProperties(EncodedResource resource) throws IOException // 使用给定的类加载器,从指定的类路径资源加载所有属性 public static Properties loadAllProperties(String resourceName, @Nullable ClassLoader classLoader) throws IOException ......类加载工具:ClassUtils// 把包路径转化为文件路径 public static String convertClassNameToResourcePath(String className) // 返回给定实例所有接口,包括由超类实现的。 public static Class<?>[] getAllInterfaces(Object instance) // 获取类的包名 public static String getPackageName(Class<?> clazz) // 判断类是否存在给定方法 public static boolean hasMethod(Class<?> clazz, Method method) ......反射工具类:ReflectionUtils// 方法调用 public static Object invokeMethod(Method method, @Nullable Object target) // 设置方法可访问 public static void makeAccessible(Method method) // 获取给定类的所有方法 public static Method[] getAllDeclaredMethods(Class<?> leafClass) ......IP地址匹配器:IpAddressMatcher// ip地址匹配 public boolean matches(HttpServletRequest request) ......注解工具类:AnnotatedElementUtils// 判断类上是否有某个注解 public static boolean hasAnnotation(AnnotatedElement element, Class<? extends Annotation> annotationType) ......