引入工具包
| <dependency> |
| <groupId>org.springframework</groupId> |
| <artifactId>spring-core</artifactId> |
| <version>5.3.10</version> |
| </dependency> |
断言
1,断言是一个逻辑判断,用于检查不应该发生的情况
2,Assert 关键字在 JDK1.4 中引入,可通过 JVM 参数-enableassertions开启
3,SpringBoot 中提供了 Assert 断言工具类,通常用于数据合法性检查
| |
| |
| void notNull(Object object, String message) |
| |
| |
| void isNull(Object object, String message) |
| |
| void isTrue(boolean expression, String message) |
| |
| void notEmpty(Collection collection, String message) |
| |
| void hasLength(String text, String message) |
| |
| void hasText(String text, String message) |
| |
| void isInstanceOf(Class type, Object obj, String message) |
| |
| void isAssignable(Class superType, Class subType, String message) |
对象、数组、集合
ObjectUtils
获取对象的基本信息
| |
| String nullSafeClassName(Object obj) |
| |
| int nullSafeHashCode(Object object) |
| |
| String nullSafeToString(boolean[] array) |
| |
| String getIdentityHexString(Object obj) |
| |
| String identityToString(Object obj) |
| |
| String getDisplayString(Object obj) |
判断工具
| |
| boolean isEmpty(Object[] array) |
| |
| boolean isArray(Object obj) |
| |
| boolean containsElement(Object[] array, Object element) |
| |
| boolean nullSafeEquals(Object o1, Object o2) |
| |
| |
| |
| |
| |
| |
| |
| |
| boolean isEmpty(Object obj) |
其他工具方法
| |
| <A, O extends A> A[] addObjectToArray(A[] array, O obj) |
| |
| Object[] toObjectArray(Object source) |
StringUtils
字符串判断工具
| |
| boolean isEmpty(Object str) |
| |
| boolean endsWithIgnoreCase(String str, String suffix) |
| |
| boolean startsWithIgnoreCase(String str, String prefix) |
| |
| boolean containsWhitespace(String str) |
| |
| boolean hasLength(CharSequence str) |
| |
| boolean hasText(CharSequence str) |
| |
| boolean substringMatch(CharSequence str, int index, CharSequence substring) |
| |
| int countOccurrencesOf(String str, String sub) |
字符串操作工具
| |
| String replace(String inString, String oldPattern, String newPattern) |
| |
| String trimTrailingCharacter(String str, char trailingCharacter) |
| |
| String trimLeadingCharacter(String str, char leadingCharacter) |
| |
| String trimLeadingWhitespace(String str) |
| |
| String trimTrailingWhitespace(String str) |
| |
| String trimWhitespace(String str) |
| |
| String trimAllWhitespace(String str) |
| |
| String delete(String inString, String pattern) |
| |
| String deleteAny(String inString, String charsToDelete) |
| |
| String[] trimArrayElements(String[] array) |
| |
| String uriDecode(String source, Charset charset) |
路径相关工具方法
| |
| String cleanPath(String path) |
| |
| String getFilename(String path) |
| |
| String getFilenameExtension(String path) |
| |
| boolean pathEquals(String path1, String path2) |
| |
| String stripFilenameExtension(String path) |
| |
| String unqualify(String qualifiedName) |
| |
| String unqualify(String qualifiedName, char separator) |
CollectionUtils
集合判断工具
| |
| boolean isEmpty(Collection<?> collection) |
| |
| boolean isEmpty(Map<?,?> map) |
| |
| boolean containsInstance(Collection<?> collection, Object element) |
| |
| boolean contains(Iterator<?> iterator, Object element) |
| |
| boolean containsAny(Collection<?> source, Collection<?> candidates) |
| |
| boolean hasUniqueObject(Collection<?> collection) |
集合操作工具
| |
| <E> void mergeArrayIntoCollection(Object array, Collection<E> collection) |
| |
| <K,V> void mergePropertiesIntoMap(Properties props, Map<K,V> map) |
| |
| <T> T lastElement(List<T> list) |
| |
| <T> T lastElement(Set<T> set) |
| |
| <E> E findFirstMatch(Collection<?> source, Collection<E> candidates) |
| |
| <T> T findValueOfType(Collection<?> collection, Class<T> type) |
| |
| Object findValueOfType(Collection<?> collection, Class<?>[] types) |
| |
| Class<?> findCommonElementType(Collection<?> collection) |
文件、资源、IO 流
FileCopyUtils
输入
| |
| byte[] copyToByteArray(File in) |
| |
| byte[] copyToByteArray(InputStream in) |
| |
| String copyToString(Reader in) |
输出
| |
| void copy(byte[] in, File out) |
| |
| int copy(File in, File out) |
| |
| void copy(byte[] in, OutputStream out) |
| |
| int copy(InputStream in, OutputStream out) |
| |
| int copy(Reader in, Writer out) |
| |
| void copy(String in, Writer out) |
ResourceUtils
从资源路径获取文件
| |
| static boolean isUrl(String resourceLocation) |
| |
| static URL getURL(String resourceLocation) |
| |
| static File getFile(String resourceLocation) |
Resource
| |
| FileSystemResource |
| |
| UrlResource |
| |
| ClassPathResource |
| |
| ServletContextResource |
| |
| boolean exists() |
| |
| File getFile() |
| |
| URI getURI() |
| |
| URL getURL() |
| |
| InputStream getInputStream() |
| |
| String getDescription() |
StreamUtils
输入
| void copy(byte[] in, OutputStream out) |
| int copy(InputStream in, OutputStream out) |
| void copy(String in, Charset charset, OutputStream out) |
| long copyRange(InputStream in, OutputStream out, long start, long end) |
输出
| byte[] copyToByteArray(InputStream in) |
| String copyToString(InputStream in, Charset charset) |
| |
| int drain(InputStream in) |
反射、AOP
ReflectionUtils
获取方法
| |
| Method findMethod(Class<?> clazz, String name) |
| |
| Method findMethod(Class<?> clazz, String name, Class<?>... paramTypes) |
| |
| Method[] getAllDeclaredMethods(Class<?> leafClass) |
| |
| Constructor<T> accessibleConstructor(Class<T> clazz, Class<?>... parameterTypes) |
| |
| boolean isEqualsMethod(Method method) |
| |
| boolean isHashCodeMethod(Method method) |
| |
| boolean isToStringMethod(Method method) |
| |
| boolean isObjectMethod(Method method) |
| |
| boolean declaresException(Method method, Class<?> exceptionType) |
执行方法
| |
| Object invokeMethod(Method method, Object target) |
| |
| Object invokeMethod(Method method, Object target, Object... args) |
| |
| void makeAccessible(Method method) |
| |
| void makeAccessible(Constructor<?> ctor) |
获取字段
| |
| Field findField(Class<?> clazz, String name) |
| |
| Field findField(Class<?> clazz, String name, Class<?> type) |
| |
| boolean isPublicStaticFinal(Field field) |
设置字段
| |
| Object getField(Field field, Object target) |
| |
| void setField(Field field, Object target, Object value) |
| |
| void shallowCopyFieldState(Object src, Object dest) |
| |
| void makeAccessible(Field field) |
| |
| void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc) |
| |
| void doWithFields(Class<?> clazz, ReflectionUtils.FieldCallback fc, |
| ReflectionUtils.FieldFilter ff) |
| |
| void doWithLocalFields(Class<?> clazz, ReflectionUtils.FieldCallback fc) |
AopUtils
判断代理类型
| |
| boolean isAopProxy() |
| |
| isJdkDynamicProxy() |
| |
| boolean isCglibProxy() |
| 获取被代理对象的 class |
| |
| Class<?> getTargetClass() |
AopContext
获取当前对象的代理对象
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2022-10-11 nginx 配置