mirror of
https://gitee.com/jzsw-it/yexuejc-base.git
synced 2025-08-02 16:59:30 +08:00
Compare commits
3 Commits
007d8d2f16
...
601611a11f
Author | SHA1 | Date | |
---|---|---|---|
601611a11f | |||
8d364b99f2 | |||
127c6902bf |
@ -1,11 +1,11 @@
|
||||
yexuejc-base 基于jdk8常用工具包
|
||||
yexuejc-base 基于jdk11常用工具包
|
||||
----------------------
|
||||
源码地址:<br>
|
||||
github:https://github.com/yexuejc/yexuejc-base
|
||||
gitee:https://gitee.com/jzsw-it/yexuejc-base
|
||||
|
||||
### 说明
|
||||
1. 支持环境:java8(1.5.0开始支持java11,请使用`x.x.x-jre11`版本)
|
||||
1. 支持环境:java11(1.5.0开始支持java11,请使用`1.5.x-jre11`版本)
|
||||
2. 该工具包基于springboot提取,按理说适用于所有java工程
|
||||
3. 其中依赖jjwt相关、validation-api,排除请使用
|
||||
> ```
|
||||
@ -23,7 +23,7 @@ gitee:https://gitee.com/jzsw-it/yexuejc-base
|
||||
7. 从`1.5.0`开始,版本分为`1.5.0-jre8`和`1.5.0-jre11`,分别对于jre8和jre11使用
|
||||
|
||||
### 使用
|
||||
>yexuejc.base.version=1.5.0-jre8
|
||||
>yexuejc.base.version=1.5.1-jre11
|
||||
|
||||
pom.xml
|
||||
```
|
||||
|
@ -1,5 +1,14 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
@ -24,15 +33,6 @@ import com.yexuejc.base.converter.LocalDateTimeSerializer;
|
||||
import com.yexuejc.base.converter.TimestampDeserializer;
|
||||
import com.yexuejc.base.converter.TimestampSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* json工具类,基于jackson
|
||||
*
|
||||
@ -42,7 +42,7 @@ import java.util.logging.Logger;
|
||||
* @date 2018/9/3 15:28
|
||||
*/
|
||||
public class JsonUtil {
|
||||
private static Logger log = Logger.getLogger(JsonUtil.class.getName());
|
||||
private static final Logger log = Logger.getLogger(JsonUtil.class.getName());
|
||||
|
||||
private JsonUtil() {
|
||||
}
|
||||
@ -50,10 +50,9 @@ public class JsonUtil {
|
||||
/**
|
||||
* 作为单例全局使用
|
||||
*/
|
||||
private static JsonMapper jsonMapper = new JsonMapper();
|
||||
private static final JsonMapper jsonMapper = new JsonMapper();
|
||||
|
||||
static {
|
||||
JsonUtil.setJavaTimeModule(JsonUtil.jsonMapper);
|
||||
JsonUtil.initDefaultObjectMapper(JsonUtil.jsonMapper);
|
||||
}
|
||||
|
||||
@ -94,14 +93,17 @@ public class JsonUtil {
|
||||
* </pre>
|
||||
*
|
||||
* @param jsonMapper
|
||||
* @return
|
||||
*/
|
||||
private static void initDefaultObjectMapper(ObjectMapper jsonMapper) {
|
||||
private static ObjectMapper initDefaultObjectMapper(ObjectMapper jsonMapper) {
|
||||
JsonUtil.setJavaTimeModule(jsonMapper);
|
||||
//值为空时,NON_NULL:舍去字段;ALWAYS:保留字段
|
||||
jsonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
jsonMapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
|
||||
jsonMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
|
||||
jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
jsonMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
return jsonMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,8 +123,7 @@ public class JsonUtil {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static ObjectMapper acceptEmptyStringAsNullObject() {
|
||||
JsonMapper jsonMapper = new JsonMapper();
|
||||
public static ObjectMapper acceptEmptyStringAsNullObject(JsonMapper jsonMapper) {
|
||||
setJavaTimeModule(jsonMapper);
|
||||
//值为空时,ALWAYS:保留字段,默认字符串值为“”,对象值为null
|
||||
jsonMapper.setSerializationInclusion(JsonInclude.Include.ALWAYS);
|
||||
|
@ -1,8 +1,7 @@
|
||||
package com.yexuejc.base.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.lang.reflect.Array;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
@ -11,9 +10,9 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -33,36 +32,25 @@ public final class StrUtil {
|
||||
private static char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
/**
|
||||
* 判断字符串,数组,集合 是否为空
|
||||
* 判断字符串,数组,集合 是否为空(null,"",[],{})
|
||||
*
|
||||
* @param obj
|
||||
* @param obj 対象
|
||||
* @return true:空;false:非空
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmpty(Object obj) {
|
||||
if (obj instanceof String) {
|
||||
if (obj == null || "".equals((String) obj)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Object[]) {
|
||||
if (obj == null || ((Object[]) obj).length == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Collection<?>) {
|
||||
if (obj == null || ((Collection<?>) obj).size() == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
if (obj == null) {
|
||||
return true;
|
||||
} else if (obj instanceof Optional) {
|
||||
return ((Optional<?>) obj).isEmpty();
|
||||
} else if (obj instanceof CharSequence) {
|
||||
return ((CharSequence) obj).length() == 0;
|
||||
} else if (obj.getClass().isArray()) {
|
||||
return Array.getLength(obj) == 0;
|
||||
} else if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).isEmpty();
|
||||
} else {
|
||||
if (obj == null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return obj instanceof Map && ((Map<?, ?>) obj).isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user