From d98faaffee6627655bf584a79e968656012adf84 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子li <15040126243@163.com>
Date: 星期日, 13 六月 2021 15:39:35 +0800
Subject: [PATCH] update 移除 fastjson 增加 jackson 工具类 重写相关业务
---
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java | 26 ++--
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java | 111 +++++++++---------
ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java | 4
ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java | 91 +++++++++++++++
ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java | 6
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java | 34 +++--
ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java | 4
ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java | 10 +
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java | 38 ++---
pom.xml | 8 -
ruoyi-admin/src/main/resources/application.yml | 2
ruoyi-common/pom.xml | 6 -
12 files changed, 207 insertions(+), 133 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4a73f1e..4beed40 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,6 @@
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
<druid.version>1.2.6</druid.version>
<knife4j.version>3.0.2</knife4j.version>
- <fastjson.version>1.2.76</fastjson.version>
<poi.version>4.1.2</poi.version>
<velocity.version>1.7</velocity.version>
<jwt.version>0.9.1</jwt.version>
@@ -71,13 +70,6 @@
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>${velocity.version}</version>
- </dependency>
-
- <!-- 闃块噷JSON瑙f瀽鍣� -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- <version>${fastjson.version}</version>
</dependency>
<!-- Token鐢熸垚涓庤В鏋�-->
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index 0465095..563931b 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -11,7 +11,7 @@
# 鏂囦欢璺緞
profile: ./ruoyi/uploadPath
# 鑾峰彇ip鍦板潃寮�鍏�
- addressEnabled: false
+ addressEnabled: true
captcha:
# 楠岃瘉鐮佸紑鍏�
diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml
index c6275c2..c55be1c 100644
--- a/ruoyi-common/pom.xml
+++ b/ruoyi-common/pom.xml
@@ -53,12 +53,6 @@
<artifactId>jackson-databind</artifactId>
</dependency>
- <!-- 闃块噷JSON瑙f瀽鍣� -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>fastjson</artifactId>
- </dependency>
-
<!-- excel宸ュ叿 -->
<dependency>
<groupId>org.apache.poi</groupId>
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java
new file mode 100644
index 0000000..2607636
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/JsonUtils.java
@@ -0,0 +1,91 @@
+package com.ruoyi.common.utils;
+
+import cn.hutool.core.util.ArrayUtil;
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JSON 宸ュ叿绫�
+ *
+ * @author 鑺嬮亾婧愮爜
+ */
+public class JsonUtils {
+
+ private static ObjectMapper objectMapper = new ObjectMapper();
+
+ /**
+ * 鍒濆鍖� objectMapper 灞炴��
+ * <p>
+ * 閫氳繃杩欐牱鐨勬柟寮忥紝浣跨敤 Spring 鍒涘缓鐨� ObjectMapper Bean
+ *
+ * @param objectMapper ObjectMapper 瀵硅薄
+ */
+ public static void init(ObjectMapper objectMapper) {
+ JsonUtils.objectMapper = objectMapper;
+ }
+
+ public static String toJsonString(Object object) {
+ try {
+ return objectMapper.writeValueAsString(object);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <T> T parseObject(String text, Class<T> clazz) {
+ if (StrUtil.isEmpty(text)) {
+ return null;
+ }
+ try {
+ return objectMapper.readValue(text, clazz);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <T> T parseObject(byte[] bytes, Class<T> clazz) {
+ if (ArrayUtil.isEmpty(bytes)) {
+ return null;
+ }
+ try {
+ return objectMapper.readValue(bytes, clazz);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <T> T parseObject(String text, TypeReference<T> typeReference) {
+ try {
+ return objectMapper.readValue(text, typeReference);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <T> Map<String, T> parseMap(String text) {
+ try {
+ return objectMapper.readValue(text, new TypeReference<Map<String, T>>() {});
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static <T> List<T> parseArray(String text, Class<T> clazz) {
+ if (StrUtil.isEmpty(text)) {
+ return new ArrayList<>();
+ }
+ try {
+ return objectMapper.readValue(text, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
index 2093e19..4b678b3 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ip/AddressUtils.java
@@ -3,10 +3,12 @@
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
-import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.constant.Constants;
+import com.ruoyi.common.utils.JsonUtils;
import lombok.extern.slf4j.Slf4j;
+
+import java.util.Map;
/**
* 鑾峰彇鍦板潃绫�
@@ -38,9 +40,9 @@
log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip);
return UNKNOWN;
}
- JSONObject obj = JSONObject.parseObject(rspStr);
- String region = obj.getString("pro");
- String city = obj.getString("city");
+ Map<String, String> obj = JsonUtils.parseMap(rspStr);
+ String region = obj.get("pro");
+ String city = obj.get("city");
return String.format("%s %s", region, city);
} catch (Exception e) {
log.error("鑾峰彇鍦扮悊浣嶇疆寮傚父 {}", ip);
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
index 280a60c..d5c0fe8 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
@@ -2,11 +2,11 @@
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSON;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.BusinessStatus;
import com.ruoyi.common.enums.HttpMethod;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.AsyncService;
@@ -30,7 +30,6 @@
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.Collection;
-import java.util.Iterator;
import java.util.Map;
/**
@@ -94,7 +93,7 @@
String ip = ServletUtils.getClientIP();
operLog.setOperIp(ip);
// 杩斿洖鍙傛暟
- operLog.setJsonResult(JSON.toJSONString(jsonResult));
+ operLog.setJsonResult(JsonUtils.toJsonString(jsonResult));
operLog.setOperUrl(ServletUtils.getRequest().getRequestURI());
if (loginUser != null)
@@ -192,19 +191,16 @@
*/
private String argsArrayToString(Object[] paramsArray)
{
- String params = "";
+ StringBuilder params = new StringBuilder();
if (paramsArray != null && paramsArray.length > 0)
{
- for (int i = 0; i < paramsArray.length; i++)
- {
- if (Validator.isNotNull(paramsArray[i]) && !isFilterObject(paramsArray[i]))
- {
- Object jsonObj = JSON.toJSON(paramsArray[i]);
- params += jsonObj.toString() + " ";
- }
- }
+ for (Object o : paramsArray) {
+ if (Validator.isNotNull(o) && !isFilterObject(o)) {
+ params.append(JsonUtils.toJsonString(o)).append(" ");
+ }
+ }
}
- return params.trim();
+ return params.toString().trim();
}
/**
@@ -224,19 +220,17 @@
else if (Collection.class.isAssignableFrom(clazz))
{
Collection collection = (Collection) o;
- for (Iterator iter = collection.iterator(); iter.hasNext();)
- {
- return iter.next() instanceof MultipartFile;
- }
+ for (Object value : collection) {
+ return value instanceof MultipartFile;
+ }
}
else if (Map.class.isAssignableFrom(clazz))
{
Map map = (Map) o;
- for (Iterator iter = map.entrySet().iterator(); iter.hasNext();)
- {
- Map.Entry entry = (Map.Entry) iter.next();
- return entry.getValue() instanceof MultipartFile;
- }
+ for (Object value : map.entrySet()) {
+ Map.Entry entry = (Map.Entry) value;
+ return entry.getValue() instanceof MultipartFile;
+ }
}
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|| o instanceof BindingResult;
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java
index d310382..bd0e99e 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/RepeatSubmitInterceptor.java
@@ -1,55 +1,56 @@
-package com.ruoyi.framework.interceptor;
-
-import java.lang.reflect.Method;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import org.springframework.stereotype.Component;
-import org.springframework.web.method.HandlerMethod;
-import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
-import com.alibaba.fastjson.JSONObject;
-import com.ruoyi.common.annotation.RepeatSubmit;
-import com.ruoyi.common.core.domain.AjaxResult;
-import com.ruoyi.common.utils.ServletUtils;
-
-/**
- * 闃叉閲嶅鎻愪氦鎷︽埅鍣�
- *
- * @author ruoyi
- */
-@Component
-public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
-{
- @Override
- public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
- {
- if (handler instanceof HandlerMethod)
- {
- HandlerMethod handlerMethod = (HandlerMethod) handler;
- Method method = handlerMethod.getMethod();
- RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class);
- if (annotation != null)
- {
- if (this.isRepeatSubmit(request))
- {
- AjaxResult ajaxResult = AjaxResult.error("涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍚庡啀璇�");
- ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult));
- return false;
- }
- }
- return true;
- }
- else
- {
- return super.preHandle(request, response, handler);
- }
- }
-
- /**
- * 楠岃瘉鏄惁閲嶅鎻愪氦鐢卞瓙绫诲疄鐜板叿浣撶殑闃查噸澶嶆彁浜ょ殑瑙勫垯
- *
- * @param request
- * @return
- * @throws Exception
- */
- public abstract boolean isRepeatSubmit(HttpServletRequest request);
-}
+package com.ruoyi.framework.interceptor;
+
+import com.ruoyi.common.annotation.RepeatSubmit;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.JsonUtils;
+import com.ruoyi.common.utils.ServletUtils;
+import org.springframework.stereotype.Component;
+import org.springframework.web.method.HandlerMethod;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+
+/**
+ * 闃叉閲嶅鎻愪氦鎷︽埅鍣�
+ *
+ * @author ruoyi
+ */
+@Component
+public abstract class RepeatSubmitInterceptor extends HandlerInterceptorAdapter
+{
+ @Override
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
+ {
+ if (handler instanceof HandlerMethod)
+ {
+ HandlerMethod handlerMethod = (HandlerMethod) handler;
+ Method method = handlerMethod.getMethod();
+ RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class);
+ if (annotation != null)
+ {
+ if (this.isRepeatSubmit(request))
+ {
+ AjaxResult ajaxResult = AjaxResult.error("涓嶅厑璁搁噸澶嶆彁浜わ紝璇风◢鍚庡啀璇�");
+ ServletUtils.renderString(response, JsonUtils.toJsonString(ajaxResult));
+ return false;
+ }
+ }
+ return true;
+ }
+ else
+ {
+ return super.preHandle(request, response, handler);
+ }
+ }
+
+ /**
+ * 楠岃瘉鏄惁閲嶅鎻愪氦鐢卞瓙绫诲疄鐜板叿浣撶殑闃查噸澶嶆彁浜ょ殑瑙勫垯
+ *
+ * @param request
+ * @return
+ * @throws Exception
+ */
+ public abstract boolean isRepeatSubmit(HttpServletRequest request);
+}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
index b6cdfac..bc09231 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java
@@ -2,10 +2,10 @@
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Validator;
-import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.filter.RepeatedlyRequestWrapper;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -69,7 +69,7 @@
// body鍙傛暟涓虹┖锛岃幏鍙朠arameter鐨勬暟鎹�
if (Validator.isEmpty(nowParams))
{
- nowParams = JSONObject.toJSONString(request.getParameterMap());
+ nowParams = JsonUtils.toJsonString(request.getParameterMap());
}
Map<String, Object> nowDataMap = new HashMap<String, Object>();
nowDataMap.put(REPEAT_PARAMS, nowParams);
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java
index 0ff60e2..1cd8d60 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/AuthenticationEntryPointImpl.java
@@ -2,8 +2,8 @@
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpStatus;
-import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.ServletUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
@@ -16,7 +16,7 @@
/**
* 璁よ瘉澶辫触澶勭悊绫� 杩斿洖鏈巿鏉�
- *
+ *
* @author ruoyi
*/
@Component
@@ -30,6 +30,6 @@
{
int code = HttpStatus.HTTP_UNAUTHORIZED;
String msg = StrUtil.format("璇锋眰璁块棶锛歿}锛岃璇佸け璐ワ紝鏃犳硶璁块棶绯荤粺璧勬簮", request.getRequestURI());
- ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg)));
+ ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(code, msg)));
}
}
diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
index 3ce2447..2a12126 100644
--- a/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
+++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/security/handle/LogoutSuccessHandlerImpl.java
@@ -2,10 +2,10 @@
import cn.hutool.core.lang.Validator;
import cn.hutool.http.HttpStatus;
-import com.alibaba.fastjson.JSON;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.AsyncService;
import com.ruoyi.framework.web.service.TokenService;
@@ -47,7 +47,7 @@
// 璁板綍鐢ㄦ埛閫�鍑烘棩蹇�
asyncService.recordLogininfor(userName, Constants.LOGOUT, "閫�鍑烘垚鍔�", request);
}
- ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.HTTP_OK, "閫�鍑烘垚鍔�")));
+ ServletUtils.renderString(response, JsonUtils.toJsonString(AjaxResult.error(HttpStatus.HTTP_OK, "閫�鍑烘垚鍔�")));
}
}
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
index 1568824..961bf31 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
@@ -3,8 +3,6 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -12,6 +10,7 @@
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.CustomException;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.PageUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.file.FileUtils;
@@ -130,7 +129,7 @@
@Override
@Transactional
public void updateGenTable(GenTable genTable) {
- String options = JSON.toJSONString(genTable.getParams());
+ String options = JsonUtils.toJsonString(genTable.getParams());
genTable.setOptions(options);
int row = baseMapper.updateById(genTable);
if (row > 0) {
@@ -361,13 +360,12 @@
@Override
public void validateEdit(GenTable genTable) {
if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
- String options = JSON.toJSONString(genTable.getParams());
- JSONObject paramsObj = JSONObject.parseObject(options);
- if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) {
+ Map<String, Object> paramsObj = genTable.getParams();
+ if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_CODE))) {
throw new CustomException("鏍戠紪鐮佸瓧娈典笉鑳戒负绌�");
- } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) {
+ } else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_PARENT_CODE))) {
throw new CustomException("鏍戠埗缂栫爜瀛楁涓嶈兘涓虹┖");
- } else if (Validator.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) {
+ } else if (Validator.isEmpty(paramsObj.get(GenConstants.TREE_NAME))) {
throw new CustomException("鏍戝悕绉板瓧娈典笉鑳戒负绌�");
} else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
if (Validator.isEmpty(genTable.getSubTableName())) {
@@ -425,13 +423,13 @@
* @param genTable 璁剧疆鍚庣殑鐢熸垚瀵硅薄
*/
public void setTableFromOptions(GenTable genTable) {
- JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions());
+ Map<String, String> paramsObj = JsonUtils.parseMap(genTable.getOptions());
if (Validator.isNotNull(paramsObj)) {
- String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
- String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
- String treeName = paramsObj.getString(GenConstants.TREE_NAME);
- String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
- String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
+ String treeCode = paramsObj.get(GenConstants.TREE_CODE);
+ String treeParentCode = paramsObj.get(GenConstants.TREE_PARENT_CODE);
+ String treeName = paramsObj.get(GenConstants.TREE_NAME);
+ String parentMenuId = paramsObj.get(GenConstants.PARENT_MENU_ID);
+ String parentMenuName = paramsObj.get(GenConstants.PARENT_MENU_NAME);
genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode);
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
index 69421cc..5b4bff8 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
@@ -1,10 +1,11 @@
package com.ruoyi.generator.util;
+import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.StrUtil;
-import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
import org.apache.velocity.VelocityContext;
@@ -12,10 +13,11 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
/**
* 妯℃澘澶勭悊宸ュ叿绫�
- *
+ *
* @author ruoyi
*/
public class VelocityUtils
@@ -75,7 +77,7 @@
public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
{
String options = genTable.getOptions();
- JSONObject paramsObj = JSONObject.parseObject(options);
+ Map<String, Object> paramsObj = JsonUtils.parseMap(options);
String parentMenuId = getParentMenuId(paramsObj);
context.put("parentMenuId", parentMenuId);
}
@@ -83,7 +85,7 @@
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
{
String options = genTable.getOptions();
- JSONObject paramsObj = JSONObject.parseObject(options);
+ Map<String, Object> paramsObj = JsonUtils.parseMap(options);
String treeCode = getTreecode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj);
@@ -94,11 +96,11 @@
context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
- context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
+ context.put("tree_parent_code", paramsObj.get(GenConstants.TREE_PARENT_CODE));
}
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
- context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
+ context.put("tree_name", paramsObj.get(GenConstants.TREE_NAME));
}
}
@@ -300,11 +302,11 @@
* @param paramsObj 鐢熸垚鍏朵粬閫夐」
* @return 涓婄骇鑿滃崟ID瀛楁
*/
- public static String getParentMenuId(JSONObject paramsObj)
+ public static String getParentMenuId(Map<String, Object> paramsObj)
{
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID))
{
- return paramsObj.getString(GenConstants.PARENT_MENU_ID);
+ return Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID));
}
return DEFAULT_PARENT_MENU_ID;
}
@@ -315,11 +317,11 @@
* @param paramsObj 鐢熸垚鍏朵粬閫夐」
* @return 鏍戠紪鐮�
*/
- public static String getTreecode(JSONObject paramsObj)
+ public static String getTreecode(Map<String, Object> paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_CODE))
{
- return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
+ return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)));
}
return StrUtil.EMPTY;
}
@@ -330,11 +332,11 @@
* @param paramsObj 鐢熸垚鍏朵粬閫夐」
* @return 鏍戠埗缂栫爜
*/
- public static String getTreeParentCode(JSONObject paramsObj)
+ public static String getTreeParentCode(Map<String, Object> paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
{
- return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
+ return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)));
}
return StrUtil.EMPTY;
}
@@ -345,11 +347,11 @@
* @param paramsObj 鐢熸垚鍏朵粬閫夐」
* @return 鏍戝悕绉�
*/
- public static String getTreeName(JSONObject paramsObj)
+ public static String getTreeName(Map<String, Object> paramsObj)
{
if (paramsObj.containsKey(GenConstants.TREE_NAME))
{
- return StrUtil.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
+ return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)));
}
return StrUtil.EMPTY;
}
@@ -363,8 +365,8 @@
public static int getExpandColumn(GenTable genTable)
{
String options = genTable.getOptions();
- JSONObject paramsObj = JSONObject.parseObject(options);
- String treeName = paramsObj.getString(GenConstants.TREE_NAME);
+ Map<String, String> paramsObj = JsonUtils.parseMap(options);
+ String treeName = paramsObj.get(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns())
{
--
Gitblit v1.9.3