Procházet zdrojové kódy

Merge branch 'release/1.1.0'

tianyunperfect před 5 roky
rodič
revize
9bfbc6f7de
3 změnil soubory, kde provedl 96 přidání a 0 odebrání
  1. 21 0
      LICENSE
  2. 22 0
      README.md
  3. 53 0
      common/src/main/java/com/alvin/common/util/JsonUtil.java

+ 21 - 0
LICENSE

@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2020 田云
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 22 - 0
README.md

@@ -0,0 +1,22 @@
+# springboot-base
+可以直接使用的springboot-web架构
+
+## 项目模块
+```$xslt
+app
+common
+```
+
+### 包含功能
+
+- springboot-web示例
+- 日志打印
+- 异常捕获
+- controller Long类型数据自动转换
+
+
+### 怎么修改jar包名称
+
+1. idea右键修改包名和文件夹名称
+2. 修改父pom文件module的引用
+3. 修改当前pom文件中jar名称

+ 53 - 0
common/src/main/java/com/alvin/common/util/JsonUtil.java

@@ -0,0 +1,53 @@
+package com.alvin.common.util;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.TypeReference;
+import com.google.gson.Gson;
+
+
+/**
+ * json工具类
+ * https://www.yuque.com/tianyunperfect/ygzsw4/bv1mlg
+ * <p>
+ * JsonUtil.toObject(str,JsonHello.class)
+ * JSON.parseObject(str2, new TypeReference<List<MyDay>>(){})
+ * JSON.parseObject(str2, new TypeReference<JsonHello<Hello>>(){})
+ *
+ * @author tianyunperfect
+ * @date 2020/05/20
+ */
+public class JsonUtil {
+
+    /**
+     * 转换为json字符串
+     *
+     * @param object 对象
+     * @return {@link String}
+     */
+    public static String toJsonStr(Object object) {
+        return new Gson().toJson(object);
+    }
+
+
+    /**
+     * 将json字符串 转换为 普通类
+     *
+     * @param jsonStr json str
+     * @param clazz   clazz
+     * @return {@link T}
+     */
+    public static <T> T toObject(String jsonStr, Class<T> clazz) {
+        return JSON.parseObject(jsonStr, clazz);
+    }
+
+    /**
+     * 将json字符串 转换为 泛型类、集合等
+     *
+     * @param jsonStr        json str
+     * @param tTypeReference t型参考
+     * @return {@link T}
+     */
+    public static <T> T toObject(String jsonStr, TypeReference<T> tTypeReference) {
+        return JSON.parseObject(jsonStr, tTypeReference);
+    }
+}