Merge branch 'master' into gmaster

# Conflicts:
#	UPDATE.md
#	pom.xml
This commit is contained in:
yexuejc 2021-01-31 13:57:32 +08:00
commit 45aeabca96
5 changed files with 239 additions and 182 deletions

134
README.md
View File

@ -1,67 +1,67 @@
yexuejc-base 基于jdk8常用工具包
----------------------
源码地址:<br>
github:https://github.com/yexuejc/yexuejc-base
gitee:https://gitee.com/jzsw-it/yexuejc-base
### 说明
>1. 支持环境java8
>2. 该工具包基于springboot提取按理说适用于所有java工程
>3. 其中依赖jjwt、validation-api排除请使用
> ```
> <exclusions>
> <exclusion>
> <artifactId>xxx</artifactId>
> <groupId>xxxx</groupId>
> </exclusion>
> </exclusions>
> ```
>
>4. `1.1.9` 升级JWT为单例类
>5. `1.2.3` 修复RSA加密(签名)Base64Url 问题如需使用RSA请使用1.2.3+
>##### 6. 从`1.3.0`开始,版本维护转由`成都极致思维网络科技有限公司`向maven中央仓库发布版本同时变更组织`groupId``top.yexuejc`。使用者请尽快升级到`1.3.0`以上1.3.0代码向下兼容)
### 使用
>yexuejc.base.version=1.3.0
pom.xml
```
<dependencies>
<dependency>
<groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId>
<version>${yexuejc.base.version}</version>
</dependency>
</dependencies>
```
#### 附1.3.0之前的使用方式
pom.xml
```
<dependencies>
<dependency>
<groupId>com.yexuejc.base</groupId>
<artifactId>yexuejc-base</artifactId>
<version>1.3.0以下</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>yexuejc-nexus-public</id>
<name>yexuejc-nexus-public</name>
<url>https://nexus.yexuejc.club/repository/maven-public/</url>
</repository>
</repositories>
```
### 工具文档
[Wiki](WIKI.md)
### 更新日志
[更新记录](UPDATE.md)
#### 项目发展
本工程项目由maxf基于日常使用从[yexuejc-springboot](https://github.com/yexuejc/yexuejc-springboot.git)_准备移交版本控制_中抽离开源独立发展后续增加许多常用工具包。
使用者逐渐增多后考虑可靠性和稳定性原则,移交版本控制给`成都极致思维网络科技有限公司`管理maven包直接发布到中央仓库。
开源工程项目仍然保持继续维护和欢迎更多愿意贡献的小伙伴参与。
yexuejc-base 基于jdk8常用工具包
----------------------
源码地址:<br>
github:https://github.com/yexuejc/yexuejc-base
gitee:https://gitee.com/jzsw-it/yexuejc-base
### 说明
>1. 支持环境java8
>2. 该工具包基于springboot提取按理说适用于所有java工程
>3. 其中依赖jjwt、validation-api排除请使用
> ```
> <exclusions>
> <exclusion>
> <artifactId>xxx</artifactId>
> <groupId>xxxx</groupId>
> </exclusion>
> </exclusions>
> ```
>
>4. `1.1.9` 升级JWT为单例类
>5. `1.2.3` 修复RSA加密(签名)Base64Url 问题如需使用RSA请使用1.2.3+
>##### 6. 从`1.3.0`开始,变更组织`groupId``top.yexuejc`。使用者请尽快升级到`1.3.0`以上1.3.0代码向下兼容)
### 使用
>yexuejc.base.version=1.4.1
pom.xml
```
<dependencies>
<dependency>
<groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId>
<version>${yexuejc.base.version}</version>
</dependency>
</dependencies>
```
#### 附1.3.0之前的使用方式
pom.xml
```
<dependencies>
<dependency>
<groupId>com.yexuejc.base</groupId>
<artifactId>yexuejc-base</artifactId>
<version>1.3.0以下</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>yexuejc-nexus-public</id>
<name>yexuejc-nexus-public</name>
<url>https://nexus.yexuejc.club/repository/maven-public/</url>
</repository>
</repositories>
```
### 工具文档
[Wiki](WIKI.md)
### 更新日志
[更新记录](UPDATE.md)
#### 项目发展
本工程项目由maxf基于日常使用从[yexuejc-springboot](https://github.com/yexuejc/yexuejc-springboot.git)_准备移交版本控制_中抽离开源独立发展后续增加许多常用工具包。
使用者逐渐增多后考虑可靠性和稳定性原则,移交版本控制给`成都极致思维网络科技有限公司`管理maven包直接发布到中央仓库。
开源工程项目仍然保持继续维护和欢迎更多愿意贡献的小伙伴参与。

View File

@ -1,14 +1,19 @@
yexuejc-base 更新记录
------------------
#### version 1.4.0
**time2020-5-18 12:06:14** <br/>
#### version 1.4.1
**time2021-1-31 12:59:24** <br/>
**branch** master <br/>
**update** <br/>
>1. 更新仓库地址 https://nexus.yexuejc.club/ 为 https://nexus.yexuejc.top/
>2. 优化Execl 和 Jwt 工具
>1. 升级所有依赖
>1. 增加DateTimeUtil类的功能
#
#### version 1.4.0
**time2020-04-13 20:49:32** <br/>
**branch** master <br/>
**update** <br/>
>1. 优化Execl 和 Jwt 工具
#
#### version 1.3.9
**time2019-1-11 16:50:51** <br/>
**branch** master <br/>

121
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<name>${project.artifactId}</name>
<url>https://github.com/yexuejc/yexuejc-base</url>
@ -40,18 +40,18 @@
<properties>
<repos.yexuejc.url>https://nexus.yexuejc.top/repository/</repos.yexuejc.url>
<repos.mcworle.url>https://nexus.mcworle.com/repository/</repos.mcworle.url>
<repos.hm.url>https://nexus.hm3981.com/repository/</repos.hm.url>
<repos.aliyun.url>http://maven.aliyun.com/nexus/content/groups/public</repos.aliyun.url>
<repos.jitpack.url>https://jitpack.io</repos.jitpack.url>
<jjwt.version>0.7.0</jjwt.version>
<jjwt.version>0.9.1</jjwt.version>
<maven.compiler.verbose>true</maven.compiler.verbose>
<java.version>1.8</java.version>
<validation-api.version>1.1.0.Final</validation-api.version>
<commons-codec.version>1.10</commons-codec.version>
<commons-io.version>2.6</commons-io.version>
<bcprov-jdk15on.version>1.60</bcprov-jdk15on.version>
<guava.version>20.0</guava.version>
<apache-poi.version>3.13</apache-poi.version>
<validation-api.version>3.0.0</validation-api.version>
<commons-codec.version>1.15</commons-codec.version>
<commons-io.version>2.8.0</commons-io.version>
<bcprov-jdk15on.version>1.68</bcprov-jdk15on.version>
<guava.version>30.1-jre</guava.version>
<apache-poi.version>5.0.0</apache-poi.version>
<!-- 文件拷贝时的编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -67,9 +67,15 @@
<version>${jjwt.version}</version>
</dependency>
<!-- 数据校验框架 -->
<!-- <dependency>-->
<!-- <groupId>javax.validation</groupId>-->
<!-- <artifactId>validation-api</artifactId>-->
<!-- <version>${validation-api.version}</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>${validation-api.version}</version>
</dependency>
<!--base64使用到的依赖-->
@ -118,6 +124,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>8</source>
@ -128,7 +135,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
@ -139,48 +146,50 @@
</executions>
</plugin>
<!-- 使用spring boot的maven插件进行打包 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- 是否打出可执行的jar包(仅支持Linux格式) -->
<executable>true</executable>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<!-- <version>2.4.2</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <goals>-->
<!-- <goal>build-info</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; 是否打出可执行的jar包(仅支持Linux格式) &ndash;&gt;-->
<!-- <executable>true</executable>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- Javadoc -->
<!--<plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-javadoc-plugin</artifactId>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>jar</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-javadoc-plugin</artifactId>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>jar</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- GPG -->
<!--<plugin> &lt;!&ndash; 进行延签 &ndash;&gt;-->
<!--<groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-gpg-plugin</artifactId>-->
<!--<version>1.6</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<phase>verify</phase>-->
<!--<goals>-->
<!--<goal>sign</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!-- 进行延签 -->
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!-- <version>1.6</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
</plugins>
</build>
<repositories>
@ -226,16 +235,16 @@
<url>${repos.yexuejc.url}maven-snapshots/</url>
</snapshotRepository>
<!-- <repository>
<!--
<repository>
<id>releases</id>
<name>nexus-release</name>
<url>${repos.mcworle.url}maven-releases/</url>
<url>${repos.hm.url}maven-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>nexus-snapshots</name>
<url>${repos.mcworle.url}maven-snapshots/</url>
<url>${repos.hm.url}maven-snapshots/</url>
</snapshotRepository>-->
</distributionManagement>

View File

@ -148,6 +148,55 @@ public class DateTimeUtil {
return date;
}
/**
* LocalDate Date
*
* @param localDate
* @return
*/
public static Date parseDate(LocalDate localDate) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);
}
/**
* LocalDateTime Date
*
* @param localDateTime
* @return
*/
public static Date parseDate(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* LocalTime Date
*
* @param localTime 时间
* @return 当前日期的指定时间
*/
public static Date parseDate(LocalTime localTime) {
LocalDate localDate = LocalDate.now();
return parseDate(localDate, localTime);
}
/**
* LocalDate + LocalTime Date
*
* @param localDate 日期
* @param localTime 时间
* @return 指定日期的指定时间
*/
public static Date parseDate(LocalDate localDate, LocalTime localTime) {
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
/**
* Date ZonedDateTime
*
@ -172,30 +221,6 @@ public class DateTimeUtil {
return instant.atZone(zoneId).toLocalDateTime();
}
/**
* LocalDateTime Date
*
* @param localDateTime
* @return
*/
public static Date parseLocalDateTime(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* LocalDate Date
*
* @param localDate
* @return
*/
public static Date parseData(LocalDate localDate) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);
}
/**
* Date LocalDate
*
@ -204,9 +229,8 @@ public class DateTimeUtil {
*/
public static LocalDate parseLocalDate(Date date) {
Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone);
return localDateTime.toLocalDate();
ZoneId zoneId = ZoneId.systemDefault();
return instant.atZone(zoneId).toLocalDate();
}
/**
@ -223,30 +247,40 @@ public class DateTimeUtil {
}
/**
* Date LocalTime
* Long LocalDateTime
*
* @param localTime
* @return 当前日期的指定时间
* @param timestamp 13位毫秒
* @return
*/
public static Date parseDate(LocalTime localTime) {
LocalDate localDate = LocalDate.now();
return parseDate(localDate, localTime);
public static LocalDateTime parseLocalDateTime13(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp);
ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
}
/**
* Date LocalTime
* Long LocalDateTime
*
* @param localDate
* @param localTime
* @return 指定日期的指定时间
* @param timestamp 10位
* @return
*/
public static Date parseDate(LocalDate localDate, LocalTime localTime) {
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
public static LocalDateTime parseLocalDateTime10(long timestamp) {
Instant instant = Instant.ofEpochMilli(timestamp * 1000);
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
return LocalDateTime.ofInstant(instant, zone);
}
/**
* LocalDateTime Long
*
* @param localDateTime
* @return 13位毫秒
*/
public static long parseLong(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return instant.toEpochMilli();
}
/**
* 格式化时间 <br/>
* 格式 yyyy-MM-dd HH:mm:ss
@ -255,7 +289,7 @@ public class DateTimeUtil {
* @return
*/
public static String format(LocalDateTime dateTime) {
return format(dateTime, "");
return format(dateTime, null);
}
/**
@ -273,22 +307,23 @@ public class DateTimeUtil {
return df.format(dateTime);
}
/** public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(zonedDateTime2Date(ZonedDateTime.now())));
System.out.println(df2.format(date2ZonedDateTime(new Date())));
System.out.println(getWeek4First());
System.out.println(format(getWeek4First(LocalDate.parse("2018-02-10")).atTime(LocalTime.MIN)));
System.out.println(format(getWeek4Last(LocalDate.parse("2018-02-10")).atTime(LocalTime.MAX)));
/** public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(zonedDateTime2Date(ZonedDateTime.now())));
System.out.println(df2.format(date2ZonedDateTime(new Date())));
System.out.println(format(getMonth4First().atTime(LocalTime.MIN)));
System.out.println(format(getMonth4Last().atTime(LocalTime.MAX)));
System.out.println(getWeek4First());
System.out.println(format(getWeek4First(LocalDate.parse("2018-02-10")).atTime(LocalTime.MIN)));
System.out.println(format(getWeek4Last(LocalDate.parse("2018-02-10")).atTime(LocalTime.MAX)));
System.out.println(format(getYear4First().atTime(LocalTime.MIN)));
System.out.println(format(getYear4Last().atTime(LocalTime.MAX)));
System.out.println(format(getMonth4First().atTime(LocalTime.MIN)));
System.out.println(format(getMonth4Last().atTime(LocalTime.MAX)));
}*/
System.out.println(format(getYear4First().atTime(LocalTime.MIN)));
System.out.println(format(getYear4Last().atTime(LocalTime.MAX)));
}*/
}

View File

@ -2,18 +2,26 @@ package com.yexuejc.base.util;
import java.lang.annotation.*;
/**
* json转换时的格式指定
*
* @author: yexuejc
* @date: 2021-01-31 12:48:29
*/
@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ToUeProperty {
/**
* 字段名默认该字段转下划线
*
* @return
*/
String value() default "";
/**
* 是否忽略该字段默认false
*
* @return
*/
boolean ignore() default false;