init web
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.sunyard.chsm</groupId>
|
||||
<artifactId>chsm</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>chsm-common</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.sunyard.utils;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @version V1.0
|
||||
* @since 2022/12/6
|
||||
*/
|
||||
public abstract class DateFormatPattern {
|
||||
|
||||
public static final String YYYY = "yyyy";
|
||||
public static final String YYYYMMDD = "yyyyMMdd";
|
||||
public static final String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
public static final String YYYYIMMIDD = "yyyy/MM/dd";
|
||||
public static final String YYYYMMDDHHMM = "yyyyMMddHHmm";
|
||||
public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
public static final String YYYYMMDD_HHMMSS = "yyyyMMdd HHmmss";
|
||||
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
public static final String YYYY_MM_DD_HH_MM = "yyyy-MM-dd HH:mm";
|
||||
public static final String YYYYMMDDHHMMSS_SS = "yyyyMMddHHmmssSSS";
|
||||
public static final String HHMMSS_TIME_FORMAT = "HHmmss";
|
||||
public static final String YYYY_MM_DD_T_HH_MM_SS_Z = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||
public static final String YYYY_MM_DD_HH24_MM_SS = "yyyy-MM-d hh24:mm:ss";
|
||||
public static final String HH_MM = "HH:mm";
|
||||
public static final String HHMM = "HHmm";
|
||||
public static final String HH_MM_SS = "HH:mm:ss";
|
||||
public static final String ZERO_HH_MM_SS = " 00:00:00";
|
||||
public static final String YYMMDD = "yyMMdd";
|
||||
public static final String YYYY_CN_MM_CN_DD_CN = "yyyy年 MM 月 dd 日";
|
||||
public static final String MM_CN_DD_CN = "MM 月 dd 日";
|
||||
public static final String BEGIN_OF_DAY = "yyyy-MM-dd 00:00:00";
|
||||
public static final String END_OF_DAY = "yyyy-MM-dd 23:59:59";
|
||||
public static final String YYYYIMMIDDHHMMSS = "yyyy/MM/dd HH:mm:ss";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.sunyard.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @version V1.0
|
||||
* @since 2020/11/25
|
||||
*/
|
||||
public abstract class JsonUtils {
|
||||
|
||||
private JsonUtils() {
|
||||
}
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
static {
|
||||
JavaTimeModule javaTimeModule = new JavaTimeModule();
|
||||
javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DateFormatPattern.HH_MM_SS)));
|
||||
javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DateFormatPattern.YYYY_MM_DD)));
|
||||
javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DateFormatPattern.YYYY_MM_DD_HH_MM_SS)));
|
||||
|
||||
javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DateFormatPattern.HH_MM_SS)));
|
||||
javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DateFormatPattern.YYYY_MM_DD)));
|
||||
javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DateFormatPattern.YYYY_MM_DD_HH_MM_SS)));
|
||||
|
||||
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
|
||||
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
OBJECT_MAPPER.registerModules(javaTimeModule);
|
||||
}
|
||||
|
||||
public static ObjectMapper objectMapper() {
|
||||
return OBJECT_MAPPER;
|
||||
}
|
||||
|
||||
public static String toJsonString(Object obj) {
|
||||
try {
|
||||
return OBJECT_MAPPER.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
//
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] toJsonBytes(Object obj) {
|
||||
try {
|
||||
return OBJECT_MAPPER.writeValueAsBytes(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
//
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static <T> T parse(String jsonStr, Class<T> type) {
|
||||
if (jsonStr == null || jsonStr.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return OBJECT_MAPPER.readValue(jsonStr, type);
|
||||
} catch (JsonProcessingException e) {
|
||||
//
|
||||
throw new IllegalArgumentException("json格式错误");
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T parse(byte[] json, Class<T> type) {
|
||||
if (json == null || json.length == 0) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return OBJECT_MAPPER.readValue(json, type);
|
||||
} catch (IOException e) {
|
||||
//
|
||||
throw new IllegalArgumentException("json格式错误");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sunyard.utils;
|
||||
|
||||
/**
|
||||
* @author liulu
|
||||
* @version V1.0
|
||||
* @since 2020/11/16
|
||||
*/
|
||||
public abstract class ThrowableUtils {
|
||||
|
||||
private ThrowableUtils() {
|
||||
}
|
||||
|
||||
|
||||
public static String buildErrorMessage(Throwable ex) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(ex.getMessage());
|
||||
StackTraceElement[] stackTrace = ex.getStackTrace();
|
||||
int i = 0;
|
||||
for (StackTraceElement stackTraceElement : stackTrace) {
|
||||
if (i++ >= 5) {
|
||||
break;
|
||||
}
|
||||
sb.append("\n\t").append(stackTraceElement.toString());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static <T extends Exception> T findException(Class<T> exClass, Throwable ex) {
|
||||
for (int i = 0; ex != null && i < 3; i++) {
|
||||
if (exClass.isAssignableFrom(ex.getClass())) {
|
||||
//noinspection unchecked
|
||||
return (T) ex;
|
||||
}
|
||||
ex = ex.getCause();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user