public class $ extends Object
| Constructor and Description |
|---|
$() |
| Modifier and Type | Method and Description |
|---|---|
static Duration |
between(Date startDate,
Date endDate)
比较2个 时间差
|
static Duration |
between(Temporal startInclusive,
Temporal endExclusive)
时间比较
|
static String |
cleanIdentifier(String param)
获取标识符,用于参数清理
|
static String |
cleanText(String txt)
清理字符串,清理出某些不可见字符和一些sql特殊字符
|
static <T> T |
clone(T source)
浅复制
|
static void |
closeQuietly(Closeable closeable)
关闭 Closeable
|
static String[] |
concat(String[] one,
String[] other)
Concatenates 2 arrays
|
static <T> T[] |
concat(T[] one,
T[] other,
Class<T> clazz)
Concatenates 2 arrays
|
static boolean |
contains(Enumeration<?> enumeration,
Object element)
判断枚举是否包含该元素
|
static boolean |
contains(Iterator<?> iterator,
Object element)
判断迭代器中是否包含元素
|
static <T> boolean |
contains(T[] array,
T element)
判断数组中是否包含元素
|
static <T> T |
convert(Object source,
Class<T> targetType)
对象类型转换
|
static <T> T |
convert(Object source,
org.springframework.core.convert.TypeDescriptor targetType)
对象类型转换
|
static <T> T |
convert(Object source,
org.springframework.core.convert.TypeDescriptor sourceType,
org.springframework.core.convert.TypeDescriptor targetType)
对象类型转换
|
static <T> List<T> |
copy(Collection<?> sourceList,
Class<T> targetClazz)
拷贝列表对象
支持 map bean copy
|
static <T> T |
copy(Object source,
Class<T> clazz)
拷贝对象,支持 Map 和 Bean
|
static void |
copy(Object source,
Object targetBean)
拷贝对象,支持 Map 和 Bean
|
static void |
copyNonNull(Object source,
Object targetBean)
拷贝对象,source 对象属性做非 null 判断
支持 map bean copy
|
static <T> List<T> |
copyProperties(Collection<?> sourceList,
Class<T> targetClazz)
拷贝列表对象,扩展 Spring 的拷贝方法
|
static <T> T |
copyProperties(Object source,
Class<T> clazz)
拷贝对象,扩展 Spring 的拷贝方法
|
static <T> List<T> |
copyWithConvert(Collection<?> sourceList,
Class<T> targetClazz)
拷贝列表对象,并对不同类型属性进行转换
支持 map bean copy
|
static <T> T |
copyWithConvert(Object source,
Class<T> clazz)
拷贝对象,并对不同类型属性进行转换
|
static String |
decodeBase64(String value)
Base64解码
|
static String |
decodeBase64(String value,
Charset charset)
Base64解码
|
static String |
decodeBase64UrlSafe(String value)
Base64URL安全解码
|
static String |
decodeBase64UrlSafe(String value,
Charset charset)
Base64URL安全解码
|
static byte[] |
decodeHex(String hexString)
字符串反序列化成 hex
|
static Object |
defaultIfNull(Object object,
Object defaultValue)
如果对象为null,返回默认值
|
static String |
encodeBase64(String value)
Base64编码
|
static String |
encodeBase64(String value,
Charset charset)
Base64编码
|
static String |
encodeBase64UrlSafe(String value)
Base64编码为URL安全
|
static String |
encodeBase64UrlSafe(String value,
Charset charset)
Base64编码为URL安全
|
static String |
encodeHex(byte[] bytes)
byte 数组序列化成 hex
|
static boolean |
endWith(CharSequence cs,
char c)
endWith char
|
static boolean |
equals(Object o1,
Object o2)
对象 eq
|
static boolean |
equalsSafe(Object o1,
Object o2)
安全的 equals
|
static String |
escapeHtml(String html)
转义HTML用于安全过滤
|
static String |
firstCharToLower(String str)
首字母变小写
|
static String |
firstCharToUpper(String str)
首字母变大写
|
static String |
format(Object object,
String pattern)
对象格式化 支持数字,date,java8时间
|
static String |
format(String message,
Map<String,?> params)
将字符串中特定模式的字符转换成map中对应的值
use: format("my name is ${name}, and i like ${like}!"
|
static String |
format(String message,
Object... arguments)
同 log 格式的 format 规则
use: format("my name is {}, and i like {}!"
|
static String |
formatDate(Date date)
日期格式化
|
static String |
formatDate(TemporalAccessor temporal)
日期时间格式化
|
static String |
formatDateTime(Date date)
日期时间格式化
|
static String |
formatDateTime(TemporalAccessor temporal)
日期时间格式化
|
static String |
formatTime(Date date)
时间格式化
|
static String |
formatTime(TemporalAccessor temporal)
时间格式化
|
static <A extends Annotation> |
getAnnotation(AnnotatedElement annotatedElement,
Class<A> annotationType)
获取Annotation注解
|
static <A extends Annotation> |
getAnnotation(org.springframework.web.method.HandlerMethod handlerMethod,
Class<A> annotationType)
获取Annotation,先找HandlerMethod,没有则再找对应的类
|
static <A extends Annotation> |
getAnnotation(Method method,
Class<A> annotationType)
获取Annotation,先找方法,没有则再找方法上的类
|
static org.springframework.core.MethodParameter |
getMethodParameter(Constructor<?> constructor,
int parameterIndex)
获取方法参数信息
|
static org.springframework.core.MethodParameter |
getMethodParameter(Method method,
int parameterIndex)
获取方法参数信息
|
static Object |
getProperty(Object bean,
String propertyName)
获取Bean的属性
|
static org.springframework.core.io.Resource |
getResource(String resourceLocation)
获取资源,注意:boot 中请不要使用 Resource getFile,应该使用 getInputStream,支持一下协议:
1. classpath:
2. file:
3. ftp:
4. http: and https:
6.
|
static File |
getTempDir()
Returns a
File representing the system temporary directory. |
static String |
getUUID()
生成uuid
|
static int |
hashCode(Object obj)
返回对象的 hashCode
|
static byte[] |
hmacMd5(byte[] bytes,
String key)
hmacMd5
|
static byte[] |
hmacMd5(String data,
String key)
hmacMd5
|
static String |
hmacMd5Hex(byte[] bytes,
String key)
hmacMd5 Hex
|
static String |
hmacMd5Hex(String data,
String key)
hmacMd5 Hex
|
static byte[] |
hmacSha1(byte[] bytes,
String key)
hmacSha1
|
static byte[] |
hmacSha1(String data,
String key)
hmacSha1
|
static String |
hmacSha1Hex(byte[] bytes,
String key)
hmacSha1 Hex
|
static String |
hmacSha1Hex(String data,
String key)
hmacSha1 Hex
|
static byte[] |
hmacSha224(byte[] bytes,
String key)
hmacSha224
|
static byte[] |
hmacSha224(String data,
String key)
hmacSha224
|
static String |
hmacSha224Hex(byte[] bytes,
String key)
hmacSha224 Hex
|
static String |
hmacSha224Hex(String data,
String key)
hmacSha224 Hex
|
static byte[] |
hmacSha256(byte[] bytes,
String key)
hmacSha256
|
static byte[] |
hmacSha256(String data,
String key)
hmacSha256
|
static String |
hmacSha256Hex(byte[] bytes,
String key)
hmacSha256 Hex
|
static String |
hmacSha256Hex(String data,
String key)
hmacSha256 Hex
|
static byte[] |
hmacSha384(byte[] bytes,
String key)
hmacSha384
|
static byte[] |
hmacSha384(String data,
String key)
hmacSha384
|
static String |
hmacSha384Hex(byte[] bytes,
String key)
hmacSha384 Hex
|
static String |
hmacSha384Hex(String data,
String key)
hmacSha384 Hex
|
static byte[] |
hmacSha512(byte[] bytes,
String key)
hmacSha512
|
static byte[] |
hmacSha512(String data,
String key)
hmacSha512
|
static String |
hmacSha512Hex(byte[] bytes,
String key)
hmacSha512 Hex
|
static String |
hmacSha512Hex(String data,
String key)
hmacSha512 Hex
|
static boolean |
isAnyBlank(CharSequence... css)
判断是否有任意一个 空字符串
|
static boolean |
isAnyBlank(Collection<CharSequence> css)
有 任意 一个 Blank
|
static boolean |
isAnyNotBlank(CharSequence... css)
有 任意 一个 Blank
|
static boolean |
isAnyNotBlank(Collection<CharSequence> css)
有 任意 一个 Blank
|
static boolean |
isArray(Object obj)
判断对象是数组
|
static boolean |
isBlank(CharSequence cs)
判断是否为空字符串
$.isBlank(null) = true
$.isBlank("") = true
$.isBlank(" ") = true
$.isBlank("12345") = false
$.isBlank(" 12345 ") = false
|
static boolean |
isEmpty(Object obj)
判断空对象 object、map、list、set、字符串、数组
|
static boolean |
isEmpty(Object[] array)
判断数组为空
|
static boolean |
isFalse(Boolean object)
判断对象为false
|
static boolean |
isNoneBlank(CharSequence... css)
判断是否全为非空字符串
|
static boolean |
isNoneBlank(Collection<CharSequence> css)
是否全非 Blank
|
static boolean |
isNotBlank(CharSequence cs)
判断不为空字符串
$.isNotBlank(null) = false
$.isNotBlank("") = false
$.isNotBlank(" ") = false
$.isNotBlank("bob") = true
$.isNotBlank(" bob ") = true
|
static boolean |
isNotEmpty(Object obj)
对象不为空 object、map、list、set、字符串、数组
|
static boolean |
isNotEmpty(Object[] array)
判断数组不为空
|
static boolean |
isNotEqual(Object o1,
Object o2)
比较两个对象是否不相等。
|
static boolean |
isNotNull(Object obj)
判断对象是否 not null
This method exists to be used as a
Predicate, context($::notNull)
|
static boolean |
isNull(Object obj)
判断对象是否为null
This method exists to be used as a
Predicate, context($::isNull)
|
static boolean |
isNumeric(CharSequence cs)
判断一个字符串是否是数字
|
static boolean |
isTrue(Boolean object)
判断对象为true
|
static String |
join(Collection<?> coll)
将集合拼接成字符串,默认使用`,`拼接
|
static String |
join(Collection<?> coll,
String delim)
将集合拼接成字符串,默认指定分隔符
|
static String |
join(Object[] arr)
将数组拼接成字符串,默认使用`,`拼接
|
static String |
join(Object[] arr,
String delim)
将数组拼接成字符串,默认指定分隔符
|
static byte[] |
md5(byte[] data)
Calculates the MD5 digest.
|
static byte[] |
md5(String data)
Calculates the MD5 digest.
|
static String |
md5Hex(byte[] bytes)
Return a hexadecimal string representation of the MD5 digest of the given bytes.
|
static String |
md5Hex(String data)
Calculates the MD5 digest and returns the value as a 32 character hex string.
|
static <T> T |
newInstance(Class<?> clazz)
实例化对象
|
static <T> T |
newInstance(String clazzStr)
实例化对象
|
static <E> List<E> |
ofImmutableList(E... es)
不可变 List
|
static <E> Set<E> |
ofImmutableSet(E... es)
不可变 Set
|
static Date |
parse(String dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static LocalDate |
parseDate(String dateStr)
将字符串转换为日期
|
static LocalDate |
parseDate(String dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static Date |
parseDate(String dateStr,
String pattern)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(String dateStr)
将字符串转换为时间
|
static LocalDateTime |
parseDateTime(String dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static LocalTime |
parseTime(String dateStr)
将字符串转换为时间
|
static LocalTime |
parseTime(String dateStr,
DateTimeFormatter formatter)
将字符串转换为时间
|
static <T> List<List<T>> |
partition(List<T> list,
int size)
list 分片
|
static String |
random(int count)
随机数生成
|
static String |
random(int count,
RandomType randomType)
随机数生成
|
static <T> T |
readJson(byte[] bytes,
Class<T> valueType)
将json byte 数组反序列化成对象
|
static <T> T |
readJson(byte[] bytes,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
将json反序列化成对象
|
static <T> T |
readJson(InputStream in,
Class<T> valueType)
将json反序列化成对象
|
static <T> T |
readJson(String jsonString,
Class<T> valueType)
将json反序列化成对象
|
static <T> T |
readJson(String jsonString,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
将json反序列化成对象
|
static <T> T |
readJsonAsJson(InputStream in,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
将json反序列化成对象
|
static <T> List<T> |
readJsonAsList(byte[] content,
Class<T> elementClass)
读取集合
|
static <T> List<T> |
readJsonAsList(InputStream content,
Class<T> elementClass)
读取集合
|
static <T> List<T> |
readJsonAsList(String content,
Class<T> elementClass)
读取集合
|
static <K,V> Map<K,V> |
readJsonAsMap(byte[] content,
Class<?> keyClass,
Class<?> valueClass)
读取集合
|
static <K,V> Map<K,V> |
readJsonAsMap(InputStream content,
Class<?> keyClass,
Class<?> valueClass)
读取集合
|
static <K,V> Map<K,V> |
readJsonAsMap(String content,
Class<?> keyClass,
Class<?> valueClass)
读取集合
|
static byte[] |
readToByteArray(File file)
读取文件为 byte 数组
|
static byte[] |
readToByteArray(InputStream input)
InputStream to bytes 数组
|
static String |
readToString(File file)
读取文件为字符串
|
static String |
readToString(File file,
Charset encoding)
读取文件为字符串
|
static String |
readToString(InputStream input)
InputStream to String utf-8
|
static String |
readToString(InputStream input,
Charset charset)
InputStream to String
|
static com.fasterxml.jackson.databind.JsonNode |
readTree(byte[] content)
将json字符串转成 JsonNode
|
static com.fasterxml.jackson.databind.JsonNode |
readTree(InputStream in)
将json字符串转成 JsonNode
|
static com.fasterxml.jackson.databind.JsonNode |
readTree(com.fasterxml.jackson.core.JsonParser jsonParser)
将json字符串转成 JsonNode
|
static com.fasterxml.jackson.databind.JsonNode |
readTree(String jsonString)
将json字符串转成 JsonNode
|
static <T> T |
requireNotNull(T obj)
断言,必须不能为 null
public Foo(Bar bar) {
this.bar = $.requireNotNull(bar);
}
|
static <T> T |
requireNotNull(T obj,
String message)
断言,必须不能为 null
public Foo(Bar bar, Baz baz) {
this.bar = $.requireNotNull(bar, "bar must not be null");
this.baz = $.requireNotNull(baz, "baz must not be null");
}
|
static <T> T |
requireNotNull(T obj,
Supplier<String> messageSupplier)
断言,必须不能为 null
public Foo(Bar bar, Baz baz) {
this.bar = $.requireNotNull(bar, () -> "bar must not be null");
}
|
static void |
setProperty(Object bean,
String propertyName,
Object value)
设置Bean属性
|
static byte[] |
sha1(byte[] bytes)
sha1
|
static byte[] |
sha1(String data)
sha1
|
static String |
sha1Hex(byte[] bytes)
sha1Hex
|
static String |
sha1Hex(String data)
sha1Hex
|
static byte[] |
sha224(byte[] bytes)
SHA224
|
static byte[] |
sha224(String data)
SHA224
|
static String |
sha224Hex(byte[] bytes)
SHA224Hex
|
static String |
sha224Hex(String data)
SHA224Hex
|
static byte[] |
sha256(byte[] bytes)
sha256Hex
|
static byte[] |
sha256(String data)
sha256Hex
|
static String |
sha256Hex(byte[] bytes)
sha256Hex
|
static String |
sha256Hex(String data)
sha256Hex
|
static byte[] |
sha384(byte[] bytes)
sha384
|
static byte[] |
sha384(String data)
sha384
|
static String |
sha384Hex(byte[] bytes)
sha384Hex
|
static String |
sha384Hex(String data)
sha384Hex
|
static byte[] |
sha512(byte[] bytes)
sha512Hex
|
static byte[] |
sha512(String data)
sha512Hex
|
static String |
sha512Hex(byte[] bytes)
sha512Hex
|
static String |
sha512Hex(String data)
sha512Hex
|
static boolean |
simpleMatch(String[] patterns,
String str)
字符串是否符合指定的 表达式
pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
|
static boolean |
simpleMatch(String pattern,
String str)
字符串是否符合指定的 表达式
pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
|
static String[] |
split(String str,
String delimiter)
分割 字符串
|
static String[] |
splitTrim(String str,
String delimiter)
分割 字符串 删除常见 空白符
|
static boolean |
startWith(CharSequence cs,
char c)
startWith char
|
static String |
to62Str(long num)
将 long 转短字符串 为 62 进制
|
static <T> T |
toBean(Map<String,Object> beanMap,
Class<T> valueType)
将map 转为 bean
|
static Boolean |
toBoolean(Object object)
对象转为 Boolean
|
static Boolean |
toBoolean(Object object,
Boolean defaultValue)
对象转为 Boolean
|
static byte |
toByte(Object object)
对象转为 Byte
|
static byte |
toByte(Object object,
byte defaultValue)
对象转为 Byte
|
static double |
toDouble(Object object)
对象转为 Double
|
static double |
toDouble(Object object,
double defaultValue)
对象转为 Double
|
static float |
toFloat(Object object)
对象转为 Float
|
static float |
toFloat(Object object,
float defaultValue)
对象转为 Float
|
static int |
toInt(Object object)
对象转为 int (支持 String 和 Number),默认: 0
|
static int |
toInt(Object object,
int defaultValue)
对象转为 int (支持 String 和 Number)
|
static String |
toJson(Object object)
将对象序列化成json字符串
|
static byte[] |
toJsonAsBytes(Object object)
将对象序列化成 json byte 数组
|
static <E> List<E> |
toList(Iterable<E> elements)
Iterable 转换为List集合
|
static long |
toLong(Object object)
对象转为 long (支持 String 和 Number),默认: 0L
|
static long |
toLong(Object object,
long defaultValue)
对象转为 long (支持 String 和 Number),默认: 0L
|
static <K,V> Map<K,V> |
toMap(Object... keysValues)
将key value 数组转为 map
|
static Map<String,Object> |
toMap(Object bean)
将对象装成map形式,map 不可写
|
static Map<String,Object> |
toNewMap(Object bean)
将对象装成map形式,map 可写
|
static short |
toShort(Object object)
对象转为 Short
|
static short |
toShort(Object object,
short defaultValue)
对象转为 Short
|
static String |
toStr(Object object)
强转string
|
static String |
toStr(Object object,
String defaultValue)
强转string
|
static File |
toTempDir(String subDirFile)
拼接临时文件目录.
|
static String |
toTempDirPath(String subDirFile)
拼接临时文件目录.
|
static String |
urlDecode(String source)
url 解码
|
static String |
urlDecode(String source,
Charset charset)
url 解码
|
static String |
urlEncode(String source)
url 编码
|
static String |
urlEncode(String source,
Charset charset)
url 编码
|
public static <T> T requireNotNull(T obj)
public Foo(Bar bar) {
this.bar = $.requireNotNull(bar);
}
T - the type of the referenceobj - the object reference to check for nullityobj if not nullNullPointerException - if obj is nullpublic static <T> T requireNotNull(T obj,
String message)
public Foo(Bar bar, Baz baz) {
this.bar = $.requireNotNull(bar, "bar must not be null");
this.baz = $.requireNotNull(baz, "baz must not be null");
}
T - the type of the referenceobj - the object reference to check for nullitymessage - detail message to be used in the event that a NullPointerException is thrownobj if not nullNullPointerException - if obj is nullpublic static <T> T requireNotNull(T obj,
Supplier<String> messageSupplier)
public Foo(Bar bar, Baz baz) {
this.bar = $.requireNotNull(bar, () -> "bar must not be null");
}
T - the type of the referenceobj - the object reference to check for nullitymessageSupplier - supplier of the detail message to be
used in the event that a NullPointerException is thrownobj if not nullNullPointerException - if obj is nullpublic static boolean isTrue(@Nullable
Boolean object)
object - 对象public static boolean isFalse(@Nullable
Boolean object)
object - 对象public static boolean isNull(@Nullable
Object obj)
This method exists to be used as a
Predicate, context($::isNull)
obj - a reference to be checked against nulltrue if the provided reference is null otherwise
falsePredicatepublic static boolean isNotNull(@Nullable
Object obj)
This method exists to be used as a
Predicate, context($::notNull)
obj - a reference to be checked against nulltrue if the provided reference is non-null
otherwise falsePredicatepublic static String firstCharToLower(String str)
str - 字符串public static String firstCharToUpper(String str)
str - 字符串public static boolean isBlank(@Nullable
CharSequence cs)
$.isBlank(null) = true
$.isBlank("") = true
$.isBlank(" ") = true
$.isBlank("12345") = false
$.isBlank(" 12345 ") = false
cs - the CharSequence to check (may be null)true if the CharSequence is not null,
its length is greater than 0, and it does not contain whitespace onlyCharacter.isWhitespace(char)public static boolean isNotBlank(@Nullable
CharSequence cs)
$.isNotBlank(null) = false
$.isNotBlank("") = false
$.isNotBlank(" ") = false
$.isNotBlank("bob") = true
$.isNotBlank(" bob ") = true
cs - the CharSequence to check, may be nulltrue if the CharSequence is
not empty and not null and not whitespaceCharacter.isWhitespace(char)public static boolean isAnyBlank(CharSequence... css)
css - CharSequencepublic static boolean isAnyBlank(Collection<CharSequence> css)
css - CharSequencepublic static boolean isNoneBlank(CharSequence... css)
css - CharSequencepublic static boolean isNoneBlank(Collection<CharSequence> css)
css - CharSequencepublic static boolean isAnyNotBlank(CharSequence... css)
css - CharSequencepublic static boolean isAnyNotBlank(Collection<CharSequence> css)
css - CharSequencepublic static boolean isArray(@Nullable
Object obj)
obj - the object to checkpublic static boolean isEmpty(@Nullable
Object obj)
obj - the object to checkpublic static boolean isNotEmpty(@Nullable
Object obj)
obj - the object to checkpublic static boolean isEmpty(@Nullable
Object[] array)
array - the array to checkpublic static boolean isNotEmpty(@Nullable
Object[] array)
array - 数组public static boolean startWith(CharSequence cs, char c)
cs - CharSequencec - charpublic static boolean endWith(CharSequence cs, char c)
cs - CharSequencec - charpublic static String format(@Nullable String message, @Nullable Map<String,?> params)
use: format("my name is ${name}, and i like ${like}!", {"name":"L.cm", "like": "Java"})
message - 需要转换的字符串params - 转换所需的键值对集合public static String format(@Nullable String message, @Nullable Object... arguments)
use: format("my name is {}, and i like {}!", "L.cm", "Java")
message - 需要转换的字符串arguments - 需要替换的变量@Nullable public static String cleanText(@Nullable String txt)
txt - 文本@Nullable public static String cleanIdentifier(@Nullable String param)
param - 参数public static boolean equalsSafe(@Nullable
Object o1,
@Nullable
Object o2)
o1 - first Object to compareo2 - second Object to compareObject.equals(Object),
Arrays.equals(long[], long[])public static boolean equals(@Nullable
Object o1,
@Nullable
Object o2)
o1 - Objecto2 - Objectpublic static boolean isNotEqual(Object o1, Object o2)
o1 - 对象1o2 - 对象2public static int hashCode(@Nullable
Object obj)
obj - Objectpublic static Object defaultIfNull(@Nullable Object object, Object defaultValue)
object - ObjectdefaultValue - 默认值public static <T> boolean contains(@Nullable
T[] array,
T element)
T - The generic tagarray - the Array to checkelement - the element to look fortrue if found, false elsepublic static boolean contains(@Nullable
Iterator<?> iterator,
Object element)
iterator - the Iterator to checkelement - the element to look fortrue if found, false otherwisepublic static boolean contains(@Nullable
Enumeration<?> enumeration,
Object element)
enumeration - the Enumeration to checkelement - the element to look fortrue if found, false otherwisepublic static String[] concat(String[] one, String[] other)
one - 数组1other - 数组2public static <T> T[] concat(T[] one,
T[] other,
Class<T> clazz)
one - 数组1other - 数组2clazz - 数组类@SafeVarargs public static <E> Set<E> ofImmutableSet(E... es)
E - 泛型es - 对象@SafeVarargs public static <E> List<E> ofImmutableList(E... es)
E - 泛型es - 对象public static <E> List<E> toList(Iterable<E> elements)
E - 泛型elements - Iterablepublic static <K,V> Map<K,V> toMap(Object... keysValues)
K - keyV - valuekeysValues - key value 数组public static <T> List<List<T>> partition(List<T> list, int size)
T - 泛型list - Listsize - 分片大小public static boolean isNumeric(CharSequence cs)
cs - the CharSequence to check, may be null@Nullable public static String toStr(@Nullable Object object)
object - Object@Nullable public static String toStr(@Nullable Object object, @Nullable String defaultValue)
object - ObjectdefaultValue - 默认值public static int toInt(@Nullable
Object object)
object - Objectpublic static int toInt(@Nullable
Object object,
int defaultValue)
object - ObjectdefaultValue - 默认值public static long toLong(@Nullable
Object object)
object - Objectpublic static long toLong(@Nullable
Object object,
long defaultValue)
object - Objectpublic static float toFloat(@Nullable
Object object)
object - Objectpublic static float toFloat(@Nullable
Object object,
float defaultValue)
object - ObjectdefaultValue - floatpublic static double toDouble(@Nullable
Object object)
object - Objectpublic static double toDouble(@Nullable
Object object,
double defaultValue)
object - ObjectdefaultValue - doublepublic static byte toByte(@Nullable
Object object)
object - Objectpublic static byte toByte(@Nullable
Object object,
byte defaultValue)
object - ObjectdefaultValue - bytepublic static short toShort(@Nullable
Object object)
object - Objectpublic static short toShort(@Nullable
Object object,
short defaultValue)
object - ObjectdefaultValue - short@Nullable public static Boolean toBoolean(@Nullable Object object)
object - Object@Nullable public static Boolean toBoolean(@Nullable Object object, @Nullable Boolean defaultValue)
object - ObjectdefaultValue - 默认值public static String to62Str(long num)
num - 数字public static String join(Collection<?> coll)
coll - the Collection to convertStringpublic static String join(Collection<?> coll, String delim)
coll - the Collection to convertdelim - the delimiter to use (typically a ",")Stringpublic static String join(Object[] arr)
arr - the array to displayStringpublic static String join(Object[] arr, String delim)
arr - the array to displaydelim - the delimiter to use (typically a ",")Stringpublic static String[] split(@Nullable String str, @Nullable String delimiter)
str - 字符串delimiter - 分割符public static String[] splitTrim(@Nullable String str, @Nullable String delimiter)
str - 字符串delimiter - 分割符public static boolean simpleMatch(@Nullable
String pattern,
@Nullable
String str)
pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
pattern - 表达式str - 字符串public static boolean simpleMatch(@Nullable
String[] patterns,
String str)
pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
patterns - 表达式 数组str - 字符串public static String getUUID()
public static String escapeHtml(String html)
html - htmlpublic static String random(int count)
count - 字符长度public static String random(int count, RandomType randomType)
count - 字符长度randomType - 随机数类别public static byte[] md5(byte[] data)
data - Data to digestpublic static byte[] md5(String data)
data - Data to digestpublic static String md5Hex(String data)
data - Data to digestpublic static String md5Hex(byte[] bytes)
bytes - the bytes to calculate the digest overpublic static byte[] sha1(String data)
data - Data to digestpublic static byte[] sha1(byte[] bytes)
bytes - Data to digestpublic static String sha1Hex(String data)
data - Data to digestpublic static String sha1Hex(byte[] bytes)
bytes - Data to digestpublic static byte[] sha224(String data)
data - Data to digestpublic static byte[] sha224(byte[] bytes)
bytes - Data to digestpublic static String sha224Hex(String data)
data - Data to digestpublic static String sha224Hex(byte[] bytes)
bytes - Data to digestpublic static byte[] sha256(String data)
data - Data to digestpublic static byte[] sha256(byte[] bytes)
bytes - Data to digestpublic static String sha256Hex(String data)
data - Data to digestpublic static String sha256Hex(byte[] bytes)
bytes - Data to digestpublic static byte[] sha384(String data)
data - Data to digestpublic static byte[] sha384(byte[] bytes)
bytes - Data to digestpublic static String sha384Hex(String data)
data - Data to digestpublic static String sha384Hex(byte[] bytes)
bytes - Data to digestpublic static byte[] sha512(String data)
data - Data to digestpublic static byte[] sha512(byte[] bytes)
bytes - Data to digestpublic static String sha512Hex(String data)
data - Data to digestpublic static String sha512Hex(byte[] bytes)
bytes - Data to digestpublic static byte[] hmacMd5(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacMd5(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacMd5Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacMd5Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static byte[] hmacSha1(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacSha1(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacSha1Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacSha1Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static byte[] hmacSha224(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacSha224(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacSha224Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacSha224Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static byte[] hmacSha256(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacSha256(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacSha256Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacSha256Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static byte[] hmacSha384(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacSha384(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacSha384Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacSha384Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static byte[] hmacSha512(String data, String key)
data - Data to digestkey - keypublic static byte[] hmacSha512(byte[] bytes,
String key)
bytes - Data to digestkey - keypublic static String hmacSha512Hex(String data, String key)
data - Data to digestkey - keypublic static String hmacSha512Hex(byte[] bytes, String key)
bytes - Data to digestkey - keypublic static String encodeHex(byte[] bytes)
bytes - bytes to encodepublic static byte[] decodeHex(String hexString)
hexString - String to decodepublic static String encodeBase64(String value)
value - 字符串public static String encodeBase64(String value, Charset charset)
value - 字符串charset - 字符集public static String encodeBase64UrlSafe(String value)
value - 字符串public static String encodeBase64UrlSafe(String value, Charset charset)
value - 字符串charset - 字符集public static String decodeBase64(String value)
value - 字符串public static String decodeBase64(String value, Charset charset)
value - 字符串charset - 字符集public static String decodeBase64UrlSafe(String value)
value - 字符串public static String decodeBase64UrlSafe(String value, Charset charset)
value - 字符串charset - 字符集public static void closeQuietly(@Nullable
Closeable closeable)
closeable - 自动关闭public static String readToString(InputStream input)
input - the InputStream to read fromNullPointerException - if the input is nullpublic static String readToString(@Nullable InputStream input, Charset charset)
input - the InputStream to read fromcharset - the CharsetNullPointerException - if the input is nullpublic static byte[] readToByteArray(@Nullable
InputStream input)
input - InputStreampublic static String readToString(File file)
file - the file to read, must not be nullnullpublic static String readToString(File file, Charset encoding)
file - the file to read, must not be nullencoding - the encoding to use, null means platform defaultnullpublic static byte[] readToByteArray(File file)
file - the file to read, must not be nullnullpublic static File getTempDir()
File representing the system temporary directory.public static org.springframework.core.io.Resource getResource(String resourceLocation) throws IOException
1. classpath: 2. file: 3. ftp: 4. http: and https: 6. C:/dir1/ and /Users/lcm
resourceLocation - 资源路径IOException - io异常@Nullable public static String toJson(@Nullable Object object)
object - javaBeanpublic static byte[] toJsonAsBytes(@Nullable
Object object)
object - javaBeanpublic static com.fasterxml.jackson.databind.JsonNode readTree(String jsonString)
jsonString - jsonStringpublic static com.fasterxml.jackson.databind.JsonNode readTree(InputStream in)
in - InputStreampublic static com.fasterxml.jackson.databind.JsonNode readTree(byte[] content)
content - contentpublic static com.fasterxml.jackson.databind.JsonNode readTree(com.fasterxml.jackson.core.JsonParser jsonParser)
jsonParser - JsonParser@Nullable
public static <T> T readJson(byte[] bytes,
Class<T> valueType)
T - T 泛型标记bytes - json bytesvalueType - class@Nullable
public static <T> T readJson(@Nullable
String jsonString,
Class<T> valueType)
T - T 泛型标记jsonString - jsonStringvalueType - class@Nullable
public static <T> T readJson(@Nullable
InputStream in,
Class<T> valueType)
T - T 泛型标记in - InputStreamvalueType - class@Nullable
public static <T> T readJson(byte[] bytes,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
T - T 泛型标记bytes - bytestypeReference - 泛型类型@Nullable
public static <T> T readJson(@Nullable
String jsonString,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
T - T 泛型标记jsonString - jsonStringtypeReference - 泛型类型@Nullable
public static <T> T readJsonAsJson(@Nullable
InputStream in,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
T - T 泛型标记in - InputStreamtypeReference - 泛型类型public static <T> List<T> readJsonAsList(@Nullable byte[] content, Class<T> elementClass)
T - 泛型content - byteselementClass - elementClasspublic static <T> List<T> readJsonAsList(@Nullable InputStream content, Class<T> elementClass)
T - 泛型content - InputStreamelementClass - elementClasspublic static <T> List<T> readJsonAsList(@Nullable String content, Class<T> elementClass)
T - 泛型content - byteselementClass - elementClasspublic static <K,V> Map<K,V> readJsonAsMap(@Nullable byte[] content, Class<?> keyClass, Class<?> valueClass)
K - 泛型V - 泛型content - byteskeyClass - key类型valueClass - 值类型public static <K,V> Map<K,V> readJsonAsMap(@Nullable InputStream content, Class<?> keyClass, Class<?> valueClass)
K - 泛型V - 泛型content - InputStreamkeyClass - key类型valueClass - 值类型public static <K,V> Map<K,V> readJsonAsMap(@Nullable String content, Class<?> keyClass, Class<?> valueClass)
K - 泛型V - 泛型content - byteskeyClass - key类型valueClass - 值类型public static String urlEncode(String source)
source - the String to be encodedpublic static String urlEncode(String source, Charset charset)
source - the String to be encodedcharset - the character encoding to encode topublic static String urlDecode(String source)
source - the encoded StringIllegalArgumentException - when the given source contains invalid encoded sequencesStringUtils.uriDecode(String, Charset),
URLDecoder.decode(String, String)public static String urlDecode(String source, Charset charset)
source - the encoded Stringcharset - the character encoding to useIllegalArgumentException - when the given source contains invalid encoded sequencesStringUtils.uriDecode(String, Charset),
URLDecoder.decode(String, String)@Nullable public static String formatDateTime(@Nullable Date date)
date - 时间@Nullable public static String formatDate(@Nullable Date date)
date - 时间@Nullable public static String formatTime(@Nullable Date date)
date - 时间public static String format(Object object, String pattern)
object - 格式化对象pattern - 表达式public static Date parseDate(String dateStr, String pattern)
dateStr - 时间字符串pattern - 表达式public static Date parse(String dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static String formatDateTime(TemporalAccessor temporal)
temporal - 时间public static String formatDate(TemporalAccessor temporal)
temporal - 时间public static String formatTime(TemporalAccessor temporal)
temporal - 时间public static LocalDateTime parseDateTime(String dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalDateTime parseDateTime(String dateStr)
dateStr - 时间字符串public static LocalDate parseDate(String dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalDate parseDate(String dateStr)
dateStr - 时间字符串public static LocalTime parseTime(String dateStr, DateTimeFormatter formatter)
dateStr - 时间字符串formatter - DateTimeFormatterpublic static LocalTime parseTime(String dateStr)
dateStr - 时间字符串public static Duration between(Temporal startInclusive, Temporal endExclusive)
startInclusive - the start instant, inclusive, not nullendExclusive - the end instant, exclusive, not nullDuration, not nullpublic static Duration between(Date startDate, Date endDate)
startDate - 开始时间endDate - 结束时间@Nullable
public static <T> T convert(@Nullable
Object source,
Class<T> targetType)
T - 泛型标记source - the source objecttargetType - the target typeIllegalArgumentException - if targetType is null,
or sourceType is null but source is not null@Nullable
public static <T> T convert(@Nullable
Object source,
org.springframework.core.convert.TypeDescriptor sourceType,
org.springframework.core.convert.TypeDescriptor targetType)
T - 泛型标记source - the source objectsourceType - the source typetargetType - the target typeIllegalArgumentException - if targetType is null,
or sourceType is null but source is not null@Nullable
public static <T> T convert(@Nullable
Object source,
org.springframework.core.convert.TypeDescriptor targetType)
T - 泛型标记source - the source objecttargetType - the target typeIllegalArgumentException - if targetType is null,
or sourceType is null but source is not nullpublic static org.springframework.core.MethodParameter getMethodParameter(Constructor<?> constructor, int parameterIndex)
constructor - 构造器parameterIndex - 参数序号public static org.springframework.core.MethodParameter getMethodParameter(Method method, int parameterIndex)
method - 方法parameterIndex - 参数序号@Nullable public static <A extends Annotation> A getAnnotation(AnnotatedElement annotatedElement, Class<A> annotationType)
A - 泛型标记annotatedElement - AnnotatedElementannotationType - 注解类@Nullable public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationType)
A - 泛型标记method - MethodannotationType - 注解类@Nullable public static <A extends Annotation> A getAnnotation(org.springframework.web.method.HandlerMethod handlerMethod, Class<A> annotationType)
A - 泛型标记handlerMethod - HandlerMethodannotationType - 注解类public static <T> T newInstance(Class<?> clazz)
T - 泛型标记clazz - 类public static <T> T newInstance(String clazzStr)
T - 泛型标记clazzStr - 类名@Nullable public static Object getProperty(@Nullable Object bean, String propertyName)
bean - beanpropertyName - 属性名public static void setProperty(Object bean, String propertyName, Object value)
bean - beanpropertyName - 属性名value - 属性值@Nullable
public static <T> T clone(@Nullable
T source)
T - 泛型标记source - 源对象@Nullable
public static <T> T copy(@Nullable
Object source,
Class<T> clazz)
T - 泛型标记source - 源对象clazz - 类名public static void copy(@Nullable
Object source,
@Nullable
Object targetBean)
source - 源对象targetBean - 需要赋值的对象public static void copyNonNull(@Nullable
Object source,
@Nullable
Object targetBean)
支持 map bean copy
source - 源对象targetBean - 需要赋值的对象@Nullable
public static <T> T copyWithConvert(@Nullable
Object source,
Class<T> clazz)
T - 泛型标记source - 源对象clazz - 类名public static <T> List<T> copy(@Nullable Collection<?> sourceList, Class<T> targetClazz)
支持 map bean copy
T - 泛型标记sourceList - 源列表targetClazz - 转换成的类型public static <T> List<T> copyWithConvert(@Nullable Collection<?> sourceList, Class<T> targetClazz)
支持 map bean copy
T - 泛型标记sourceList - 源对象列表targetClazz - 转换成的类@Nullable
public static <T> T copyProperties(@Nullable
Object source,
Class<T> clazz)
throws org.springframework.beans.BeansException
T - 泛型标记source - the source beanclazz - the target bean classorg.springframework.beans.BeansException - if the copying failedpublic static <T> List<T> copyProperties(@Nullable Collection<?> sourceList, Class<T> targetClazz) throws org.springframework.beans.BeansException
T - 泛型标记sourceList - the source list beantargetClazz - the target bean classorg.springframework.beans.BeansException - if the copying failedpublic static Map<String,Object> toMap(@Nullable Object bean)
bean - 源对象public static Map<String,Object> toNewMap(@Nullable Object bean)
bean - 源对象Copyright © 2024. All rights reserved.