11 | BeanCopyUtils // 实体bean深度拷贝
12 | ### chart
13 | EchartsData // Echarts使用类
14 |
15 | ### classes
16 | PackageUtil // 名称空间实用工具
17 |
18 | ### code
19 | CodeUtil // code码生成工具
20 | OrderNoUtil // 订单编号生成工具类
21 | QRcodeUtils // 二维码工具类
22 | RegExUtil // 正则表达式工具类
23 | SnowflakeIdWorker // 雪花编码生成工具
24 | VerificationCodeGeneration // 验证码生成工具
25 |
26 | ### collection
27 | CollectionAllUtils // List Map Set 工具集合(未完成)
28 |
29 | ### common
30 | Config // 读取配置文件工具类
31 |
32 | ### data
33 | BigDecimalUtil // 金额计算工具类
34 | NumUtil // 格式化数字工具类
35 |
36 | ### date
37 | DateUtil // 线程安全的日期工具类
38 | DateTimeUtil // 普通日期工具类
39 |
40 | ### db
41 | JDBCUtils // JDBC工具类
42 |
43 | ### encrypt
44 | AESUtil // AES加解密工具类
45 | CharTools // 字符工具类
46 | Escape // 编解码工具类
47 | MD5Util // MD5工具类
48 |
49 | ### exception
50 | ExceptionUtil // 异常处理工具类 获取异常信息栈里的具体信息
51 |
52 | ### file
53 | Dom4jHelper // Dom4j工具类
54 | FileHelper // 文件工具类 移动 复制
55 | FileUploadUtil // 文件上传工具类
56 | FileUtil // 文件工具类 常用的文件操作
57 | UploadHelper // 异常处理工具类
58 | ExcelHanlder // 普通Excel工具类
59 | ExcelUtil // 阿里 EasyExcel工具类
60 | FtpUtil // FTP工具类
61 | MD5FileCheckUtil // MD5工具类
62 | TarGzUtils // TAR包读取内部文件工具类
63 | YamlUtil // YML文件工具类
64 | ZipUtil // 解压缩工具类
65 |
66 | ### http
67 | HttpUtil // http 和 https 工具类
68 | MyX509TrustManager // HttpUtil的依赖类
69 | HttpUtils // http 和 https 工具类2
70 | CookieUtil // cookie操作工具类
71 | ApaHttpClientUtil // http 和 https 工具类3
72 | MySSLProtocolSocketFactory // ApaHttpClientUtil的依赖类
73 | IPUtils // IP工具类
74 | RestTemplateUtil // RestTemplate工具类
75 | UrlUtil // url解析工具
76 | WebTools // WEB开发常用工具类 特殊字符处理等
77 |
78 | ### image
79 | ImageUtils // 图片处理工具类
80 |
81 | ### jmh
82 |
83 | ### json
84 | JsonSchemaUtil // jsonschema对比工具类
85 | JsonSchemaUtils // jsonschema工具类
86 | JSONUtils // json工具类
87 | JsonToPojo // json转pojo工具类
88 | JsonToSchema // json转schema工具类
89 |
90 |
91 | ### other
92 | EnumUtil // 枚举工具类
93 | MyBloomFilter // 布隆过滤器
94 |
95 | ### redis
96 | RedisUtil // Jedis工具类
97 |
98 | ### spring
99 | SpringContextUtil // SpringContext工具类
100 |
101 | ### spring
102 | CharTools // 字符编码工具类
103 | StringHelper // 字符串工具类
104 | ValidateUtil // 验证工具类(车牌、手机、邮箱,待补充)
105 |
106 | ### ssh
107 | SSHHelper // SSH远程连接工具类
108 |
109 | ### string
110 | CharTools // 字符编码工具集
111 | ValidateUtil // 字符验证工具集
112 |
113 | ### thread
114 | ThreadPoolMonitor // 线程池监控工具
115 |
116 | ### version
117 | VersionIncreaseUtil.java // 版本号自增工具
118 |
119 | ### websocket
120 | WebSocketUtil // WebSocket工具类
121 |
122 |
--------------------------------------------------------------------------------
/html/echarts/demo-bar.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ECharts Demo
7 |
10 |
36 |
37 |
38 |
39 |
40 |
41 |
ECharts Java
42 |
43 |
44 |
45 |
46 |
47 |
48 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/html/echarts/demo-line1.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ECharts Demo
7 |
10 |
36 |
37 |
38 |
39 |
40 |
41 |
ECharts Java
42 |
43 |
44 |
45 |
46 |
47 |
48 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/html/echarts/demo-line2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ECharts Demo
7 |
10 |
36 |
37 |
38 |
39 |
40 |
41 |
ECharts Java
42 |
43 |
44 |
45 |
46 |
47 |
48 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/html/echarts/demo-pie.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ECharts Demo
7 |
10 |
36 |
37 |
38 |
39 |
40 |
41 |
ECharts Java
42 |
43 |
44 |
45 |
46 |
47 |
48 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/json/input.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Virat",
3 | "sport": "cricket",
4 | "age": 25,
5 | "id": 121
6 | }
--------------------------------------------------------------------------------
/json/inputSchema.json:
--------------------------------------------------------------------------------
1 | {
2 | "type" : "object",
3 | "title" : "Example Schema",
4 | "properties" : {
5 | "age" : {
6 | "type" : "integer",
7 | "description" : "Age in years",
8 | "minimum" : 0
9 | },
10 | "firstName" : {
11 | "type" : "string"
12 | },
13 | "lastName" : {
14 | "type" : "string"
15 | },
16 | "department": {
17 | "type": "object",
18 | "title": "department",
19 | "properties": {
20 | "id": {
21 | "title": "部门id",
22 | "type": "integer"
23 | },
24 | "name": {
25 | "title": "部门名称",
26 | "type": "string"
27 | }
28 | }
29 | }
30 | },
31 | "description" : "this is a input model",
32 | "required" : [ "firstName", "lastName" ]
33 | }
--------------------------------------------------------------------------------
/lib/mysql-connector-java-5.1.49.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EricLoveMia/JavaTools/1fe72617fac473a978f73136627e73a5c792c205/lib/mysql-connector-java-5.1.49.jar
--------------------------------------------------------------------------------
/params.json:
--------------------------------------------------------------------------------
1 | {"ComponentSample":{"generalParameterJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"operate\":{\"type\":\"string\",\"title\":\"操作\",\"description\":\"操作类型 sum:求和 max:求最大值\"}}}","requestJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"caseOne\":{\"type\":\"number\",\"title\":\"操作数1\"},\"caseTwo\":{\"type\":\"number\",\"title\":\"操作数2\"}}}","responseJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"description\":{\"type\":\"string\",\"title\":\"结果说明\",\"description\":\"说明\"},\"resultPoint\":{\"type\":\"number\",\"title\":\"结果值\",\"description\":\"计算的结果\"}}}"},"ComponentSample2":{"generalParameterJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"operate\":{\"type\":\"string\",\"title\":\"操作\",\"description\":\"操作类型 sum:求和 max:求最大值\"}}}","requestJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"caseOne\":{\"type\":\"number\",\"title\":\"操作数1\"},\"caseTwo\":{\"type\":\"number\",\"title\":\"操作数2\"}}}","responseJsonschema":"{\"$schema\":\"https://json-schema.org/draft/2019-09/schema\",\"type\":\"object\",\"properties\":{\"description\":{\"type\":\"string\",\"title\":\"结果说明\",\"description\":\"说明\"},\"resultPoint\":{\"type\":\"number\",\"title\":\"结果值\",\"description\":\"计算的结果\"}}}"}}
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/ToolsMain.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools;
2 |
3 | /**
4 | * @author Eric
5 | * @version 1.0
6 | * @ClassName: ToolsMain
7 | * @Description: TODO
8 | * @company lsj
9 | * @date 2019/8/1 14:35
10 | **/
11 | public class ToolsMain {
12 |
13 | public static void main(String[] args) {
14 | System.out.println("hello tools");
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/base/InputProperties.java:
--------------------------------------------------------------------------------
1 |
2 | package cn.eric.jdktools.base;
3 |
4 | import com.fasterxml.jackson.annotation.*;
5 |
6 | import javax.annotation.Generated;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 |
10 |
11 | /**
12 | * 方法入参
13 | *
14 | * 方法入参的实体类
15 | *
16 | */
17 | @JsonInclude(JsonInclude.Include.NON_NULL)
18 | @JsonPropertyOrder({
19 | "age",
20 | "name"
21 | })
22 | @Generated("jsonschema2pojo")
23 | public class InputProperties {
24 |
25 | /**
26 | * 年龄
27 | *
28 | * 填写年龄
29 | *
30 | */
31 | @JsonProperty("age")
32 | @JsonPropertyDescription("\u586b\u5199\u5e74\u9f84")
33 | private Integer age;
34 | /**
35 | * 姓名
36 | *
37 | * 填写姓名
38 | * (Required)
39 | *
40 | */
41 | @JsonProperty("name")
42 | @JsonPropertyDescription("\u586b\u5199\u59d3\u540d")
43 | private String name;
44 | @JsonIgnore
45 | private Map additionalProperties = new HashMap();
46 |
47 | /**
48 | * 年龄
49 | *
50 | * 填写年龄
51 | *
52 | */
53 | @JsonProperty("age")
54 | public Integer getAge() {
55 | return age;
56 | }
57 |
58 | /**
59 | * 年龄
60 | *
61 | * 填写年龄
62 | *
63 | */
64 | @JsonProperty("age")
65 | public void setAge(Integer age) {
66 | this.age = age;
67 | }
68 |
69 | public InputProperties withAge(Integer age) {
70 | this.age = age;
71 | return this;
72 | }
73 |
74 | /**
75 | * 姓名
76 | *
77 | * 填写姓名
78 | * (Required)
79 | *
80 | */
81 | @JsonProperty("name")
82 | public String getName() {
83 | return name;
84 | }
85 |
86 | /**
87 | * 姓名
88 | *
89 | * 填写姓名
90 | * (Required)
91 | *
92 | */
93 | @JsonProperty("name")
94 | public void setName(String name) {
95 | this.name = name;
96 | }
97 |
98 | public InputProperties withName(String name) {
99 | this.name = name;
100 | return this;
101 | }
102 |
103 | @JsonAnyGetter
104 | public Map getAdditionalProperties() {
105 | return this.additionalProperties;
106 | }
107 |
108 | @JsonAnySetter
109 | public void setAdditionalProperty(String name, Object value) {
110 | this.additionalProperties.put(name, value);
111 | }
112 |
113 | public InputProperties withAdditionalProperty(String name, Object value) {
114 | this.additionalProperties.put(name, value);
115 | return this;
116 | }
117 |
118 | @Override
119 | public String toString() {
120 | StringBuilder sb = new StringBuilder();
121 | sb.append(InputProperties.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
122 | sb.append("age");
123 | sb.append('=');
124 | sb.append(((this.age == null)?"":this.age));
125 | sb.append(',');
126 | sb.append("name");
127 | sb.append('=');
128 | sb.append(((this.name == null)?"":this.name));
129 | sb.append(',');
130 | sb.append("additionalProperties");
131 | sb.append('=');
132 | sb.append(((this.additionalProperties == null)?"":this.additionalProperties));
133 | sb.append(',');
134 | if (sb.charAt((sb.length()- 1)) == ',') {
135 | sb.setCharAt((sb.length()- 1), ']');
136 | } else {
137 | sb.append(']');
138 | }
139 | return sb.toString();
140 | }
141 |
142 | @Override
143 | public int hashCode() {
144 | int result = 1;
145 | result = ((result* 31)+((this.name == null)? 0 :this.name.hashCode()));
146 | result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
147 | result = ((result* 31)+((this.age == null)? 0 :this.age.hashCode()));
148 | return result;
149 | }
150 |
151 | @Override
152 | public boolean equals(Object other) {
153 | if (other == this) {
154 | return true;
155 | }
156 | if ((other instanceof InputProperties) == false) {
157 | return false;
158 | }
159 | InputProperties rhs = ((InputProperties) other);
160 | return ((((this.name == rhs.name)||((this.name!= null)&&this.name.equals(rhs.name)))&&((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties))))&&((this.age == rhs.age)||((this.age!= null)&&this.age.equals(rhs.age))));
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/base/Test.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.base;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.fasterxml.jackson.annotation.JsonPropertyDescription;
5 | import io.swagger.v3.oas.annotations.media.Schema;
6 |
7 | /**
8 | * Company: 苏州渠成易销网络科技有限公司
9 | *
10 | * @version 1.0.0
11 | * @description: 测试
12 | * @author: 钱旭
13 | * @date: 2022-01-07 14:29
14 | **/
15 | public class Test {
16 | // @JsonProperty(required = true,value = "name")
17 | // @JsonPropertyDescription("This is a property description")
18 |
19 | @Schema(title = "名称",description = "这是一个名称")
20 | private String name;
21 |
22 | // @JsonProperty(value = "child")
23 | // @JsonPropertyDescription("This is a property description")
24 | @Schema(title = "孩子",description = "这是一个孩子")
25 | private TestChild child;
26 |
27 | // @JsonCreator
28 | // public Test (
29 | // @JsonProperty("name") String name,
30 | // @JsonProperty("child") TestChild child) {
31 | // this.name = name;
32 | // this.child = child;
33 | // }
34 | public String getName () {
35 | return name;
36 | }
37 | public TestChild getChild () {
38 | return child;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/base/TestChild.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.base;
2 |
3 | import com.fasterxml.jackson.annotation.JsonProperty;
4 | import com.fasterxml.jackson.annotation.JsonPropertyDescription;
5 |
6 | /**
7 | * Company: 苏州渠成易销网络科技有限公司
8 | *
9 | * @version 1.0.0
10 | * @description: 测试子类
11 | * @author: 钱旭
12 | * @date: 2022-01-07 14:31
13 | **/
14 |
15 | public class TestChild {
16 | @JsonProperty(required = true)
17 | @JsonPropertyDescription("这是一个孩子")
18 | private String childName;
19 | // @JsonCreator
20 | // public TestChild (@JsonProperty("childName") String childName) {
21 | // this.childName = childName;
22 | // }
23 | //
24 | public String getChildName () {
25 | return childName;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/base64/Base64Utils.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.base64;
2 |
3 | import sun.misc.BASE64Decoder;
4 | import sun.misc.BASE64Encoder;
5 |
6 | import javax.imageio.ImageIO;
7 | import java.awt.image.BufferedImage;
8 | import java.io.*;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 |
12 | /**
13 | * @author Eric
14 | * @version 1.0
15 | * @ClassName: Base64Utils
16 | * @Description: TODO
17 | * @company lsj
18 | * @date 2018/11/16 15:33
19 | **/
20 | public class Base64Utils {
21 |
22 | public static void main(String[] args) throws Exception {
23 |
24 | //本地图片地址
25 | String url = "C:\\Users\\Eric\\Pictures\\upload\\1.jpg";
26 | //在线图片地址
27 | //String string = "http://bpic.588ku.com//element_origin_min_pic/17/03/03/7bf4480888f35addcf2ce942701c728a.jpg";
28 |
29 | String str = Base64Utils.ImageToBase64ByLocal(url);
30 |
31 | //String ste = Base64Utils.ImageToBase64ByOnline(string);
32 |
33 | System.out.println(str);
34 |
35 | //Base64Utils.Base64ToImage(str,"C:/Users/Administrator/Desktop/test1.jpg");
36 |
37 | //Base64Utils.Base64ToImage(ste, "C:/Users/Administrator/Desktop/test2.jpg");
38 | }
39 |
40 | /**
41 | * 本地图片转换成base64字符串
42 | * @param imgFile 图片本地路径
43 | * @return
44 | *
45 | * @author ZHANGJL
46 | * @dateTime 2018-02-23 14:40:46
47 | */
48 | public static String ImageToBase64ByLocal(String imgFile) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理
49 |
50 |
51 | InputStream in = null;
52 | byte[] data = null;
53 |
54 | // 读取图片字节数组
55 | try {
56 | // new FileInputStream(new File(imgFile));
57 | in = new FileInputStream(imgFile);
58 |
59 | data = new byte[in.available()];
60 | in.read(data);
61 | in.close();
62 | } catch (IOException e) {
63 | e.printStackTrace();
64 | }
65 | // 对字节数组Base64编码
66 | BASE64Encoder encoder = new BASE64Encoder();
67 |
68 | return encoder.encode(data);// 返回Base64编码过的字节数组字符串
69 | }
70 |
71 | public static String ImageToBase64ByLocal(File file) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 File类型
72 | InputStream in = null;
73 | byte[] data = null;
74 |
75 | // 读取图片字节数组
76 | try {
77 | in = new FileInputStream(file);
78 | // in = new FileInputStream(imgFile);
79 |
80 | data = new byte[in.available()];
81 | in.read(data);
82 | in.close();
83 | } catch (IOException e) {
84 | e.printStackTrace();
85 | }
86 | // 对字节数组Base64编码
87 | BASE64Encoder encoder = new BASE64Encoder();
88 | return encoder.encode(data);// 返回Base64编码过的字节数组字符串
89 | }
90 |
91 |
92 | /**
93 | * 在线图片转换成base64字符串
94 | *
95 | * @param imgURL 图片线上路径
96 | * @return
97 | *
98 | * @author ZHANGJL
99 | * @dateTime 2018-02-23 14:43:18
100 | */
101 | public static String ImageToBase64ByOnline(String imgURL) {
102 | ByteArrayOutputStream data = new ByteArrayOutputStream();
103 | try {
104 | // 创建URL
105 | URL url = new URL(imgURL);
106 | byte[] by = new byte[1024];
107 | // 创建链接
108 | HttpURLConnection conn = (HttpURLConnection) url.openConnection();
109 | conn.setRequestMethod("GET");
110 | conn.setConnectTimeout(5000);
111 | InputStream is = conn.getInputStream();
112 | // 将内容读取内存中
113 | int len = -1;
114 | while ((len = is.read(by)) != -1) {
115 | data.write(by, 0, len);
116 | }
117 | // 关闭流
118 | is.close();
119 | } catch (IOException e) {
120 | e.printStackTrace();
121 | }
122 | // 对字节数组Base64编码
123 | BASE64Encoder encoder = new BASE64Encoder();
124 | return encoder.encode(data.toByteArray());
125 | }
126 |
127 |
128 | /**
129 | * base64字符串转换成图片
130 | * @param imgStr base64字符串
131 | * @param imgFilePath 图片存放路径
132 | * @return
133 | *
134 | * @author ZHANGJL
135 | * @dateTime 2018-02-23 14:42:17
136 | */
137 | public static boolean Base64ToImage(String imgStr,String imgFilePath) { // 对字节数组字符串进行Base64解码并生成图片
138 |
139 | if (imgStr == null && imgStr.isEmpty()) // 图像数据为空
140 | return false;
141 |
142 | BASE64Decoder decoder = new BASE64Decoder();
143 | try {
144 | // Base64解码
145 | byte[] b = decoder.decodeBuffer(imgStr);
146 | for (int i = 0; i < b.length; ++i) {
147 | if (b[i] < 0) {// 调整异常数据
148 | b[i] += 256;
149 | }
150 | }
151 |
152 | OutputStream out = new FileOutputStream(imgFilePath);
153 | out.write(b);
154 | out.flush();
155 | out.close();
156 |
157 | return true;
158 | } catch (Exception e) {
159 | return false;
160 | }
161 |
162 | }
163 |
164 | /**
165 | * 通过BufferedImage 转成 base64
166 | * @author Eric
167 | * @date 14:37 2019/2/25
168 | * @params image
169 | * @throws
170 | * @return java.lang.String
171 | **/
172 | public static String ImageToBase64ByBuffered(BufferedImage image) throws IOException {
173 |
174 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
175 | ImageIO.write(image, "jpg", outputStream);
176 | BASE64Encoder encoder = new BASE64Encoder();
177 | String base64Img = encoder.encode(outputStream.toByteArray());
178 |
179 | return base64Img;
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/bean/BeanCopyUtils.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.bean;
2 |
3 | import java.io.*;
4 | import java.util.List;
5 |
6 | /**
7 | * @version 1.0.0
8 | * @description:
9 | * @author: eric
10 | * @date: 2022-08-05 17:04
11 | **/
12 | public class BeanCopyUtils {
13 |
14 | /**
15 | * Desc: 深度拷贝
16 | * Author: Jack
17 | **/
18 | public static List deepCopy(List srcList) throws IOException, ClassNotFoundException {
19 | //序列化
20 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
21 | ObjectOutputStream oos = new ObjectOutputStream(baos);
22 | oos.writeObject(srcList);
23 |
24 | //反序列化
25 | ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
26 | ObjectInputStream ois = new ObjectInputStream(bais);
27 | List desList = (List) ois.readObject();
28 | return desList;
29 | }
30 |
31 | /**
32 | * Desc: 深度拷贝
33 | * Author: Jack
34 | **/
35 | public static T deepCopy(T src) throws IOException, ClassNotFoundException {
36 | //序列化
37 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
38 | ObjectOutputStream oos = new ObjectOutputStream(baos);
39 | oos.writeObject(src);
40 |
41 | //反序列化
42 | ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
43 | ObjectInputStream ois = new ObjectInputStream(bais);
44 | T des = (T) ois.readObject();
45 | return des;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/bean/BeanToMapUtil.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.bean;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Modifier;
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * @author Eric
10 | * @version 1.0
11 | * @ClassName: BeanToMapUtil
12 | * @Description: TODO
13 | * @company lsj
14 | * @date 2019/4/24 17:18
15 | **/
16 | public class BeanToMapUtil {
17 |
18 | /**
19 | * 实体对象转成Map
20 | * @param obj 实体对象
21 | * @return
22 | */
23 | public static Map object2Map(Object obj) {
24 | Map map = new HashMap<>();
25 | if (obj == null) {
26 | return map;
27 | }
28 | Class clazz = obj.getClass();
29 | Field[] fields = clazz.getDeclaredFields();
30 | try {
31 | for (Field field : fields) {
32 | field.setAccessible(true);
33 | map.put(field.getName(), field.get(obj));
34 | }
35 | } catch (Exception e) {
36 | e.printStackTrace();
37 | }
38 | return map;
39 | }
40 |
41 | /**
42 | * 实体对象转成Map
43 | * @param obj 实体对象 string
44 | * @returnString
45 | */
46 | public static Map object2MapString(Object obj) {
47 | Map map = new HashMap<>();
48 | if (obj == null) {
49 | return map;
50 | }
51 | Class clazz = obj.getClass();
52 | Field[] fields = clazz.getDeclaredFields();
53 | try {
54 | for (Field field : fields) {
55 | field.setAccessible(true);
56 | map.put(field.getName(), field.get(obj).toString());
57 | }
58 | } catch (Exception e) {
59 | e.printStackTrace();
60 | }
61 | return map;
62 | }
63 |
64 | /**
65 | * Map转成实体对象
66 | * @param map map实体对象包含属性
67 | * @param clazz 实体对象类型
68 | * @return
69 | */
70 | public static Object map2Object(Map map, Class> clazz) {
71 | if (map == null) {
72 | return null;
73 | }
74 | Object obj = null;
75 | try {
76 | obj = clazz.newInstance();
77 |
78 | Field[] fields = obj.getClass().getDeclaredFields();
79 | for (Field field : fields) {
80 | int mod = field.getModifiers();
81 | if (Modifier.isStatic(mod) || Modifier.isFinal(mod)) {
82 | continue;
83 | }
84 | field.setAccessible(true);
85 | field.set(obj, map.get(field.getName()));
86 | }
87 | } catch (Exception e) {
88 | e.printStackTrace();
89 | }
90 | return obj;
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/cache/ICache.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.cache;
2 |
3 | import java.util.concurrent.Callable;
4 | import java.util.concurrent.ExecutionException;
5 |
6 | /**
7 | * Company: ClickPaaS
8 | *
9 | * @version 1.0.0
10 | * @description: 缓存公共接口
11 | * @author: 钱旭
12 | * @date: 2022-02-22 11:41
13 | **/
14 | public interface ICache {
15 |
16 | /**
17 | * 通过key获取缓存中的value,若不存在直接返回null
18 | */
19 | V getIfPresent(K key);
20 |
21 | /**
22 | * 添加缓存,若key存在,就覆盖旧值
23 | */
24 | void put(K key, V value);
25 |
26 | /**
27 | * 删除该key关联的缓存
28 | */
29 | void invalidate(K key);
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/cn/eric/jdktools/cache/caffeine/CaffeineCache.java:
--------------------------------------------------------------------------------
1 | package cn.eric.jdktools.cache.caffeine;
2 |
3 | import com.github.benmanes.caffeine.cache.Cache;
4 | import com.github.benmanes.caffeine.cache.Caffeine;
5 |
6 | import java.util.concurrent.TimeUnit;
7 |
8 | /**
9 | * Company: ClickPaaS
10 | *
11 | * @version 1.0.0
12 | * @description: caffeine工具
13 | * @author: 钱旭
14 | * @date: 2022-02-22 13:56
15 | **/
16 | public class CaffeineCache {
17 |
18 | static final Cache