fix 修复 JsonUtils 参数为空报错
This commit is contained in:
parent
639816369a
commit
2cdc12055d
@ -1,5 +1,6 @@
|
||||
package com.ruoyi.common.utils;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -32,6 +33,9 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static String toJsonString(Object object) {
|
||||
if (Validator.isEmpty(object)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.writeValueAsString(object);
|
||||
} catch (JsonProcessingException e) {
|
||||
@ -62,6 +66,9 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static <T> T parseObject(String text, TypeReference<T> typeReference) {
|
||||
if (StrUtil.isBlank(text)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(text, typeReference);
|
||||
} catch (IOException e) {
|
||||
@ -70,6 +77,9 @@ public class JsonUtils {
|
||||
}
|
||||
|
||||
public static <T> Map<String, T> parseMap(String text) {
|
||||
if (StrUtil.isBlank(text)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readValue(text, new TypeReference<Map<String, T>>() {});
|
||||
} catch (IOException e) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.ruoyi.generator.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@ -423,13 +424,13 @@ public class GenTableServiceImpl extends ServiceImpl<GenTableMapper, GenTable> i
|
||||
* @param genTable 设置后的生成对象
|
||||
*/
|
||||
public void setTableFromOptions(GenTable genTable) {
|
||||
Map<String, String> paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
Map<String, Object> paramsObj = JsonUtils.parseMap(genTable.getOptions());
|
||||
if (Validator.isNotNull(paramsObj)) {
|
||||
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);
|
||||
String treeCode = Convert.toStr(paramsObj.get(GenConstants.TREE_CODE));
|
||||
String treeParentCode = Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE));
|
||||
String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME));
|
||||
String parentMenuId = Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_ID));
|
||||
String parentMenuName = Convert.toStr(paramsObj.get(GenConstants.PARENT_MENU_NAME));
|
||||
|
||||
genTable.setTreeCode(treeCode);
|
||||
genTable.setTreeParentCode(treeParentCode);
|
||||
|
@ -319,7 +319,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreecode(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (paramsObj.containsKey(GenConstants.TREE_CODE))
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_CODE))
|
||||
{
|
||||
return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_CODE)));
|
||||
}
|
||||
@ -334,7 +334,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreeParentCode(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_PARENT_CODE))
|
||||
{
|
||||
return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_PARENT_CODE)));
|
||||
}
|
||||
@ -349,7 +349,7 @@ public class VelocityUtils
|
||||
*/
|
||||
public static String getTreeName(Map<String, Object> paramsObj)
|
||||
{
|
||||
if (paramsObj.containsKey(GenConstants.TREE_NAME))
|
||||
if (Validator.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.TREE_NAME))
|
||||
{
|
||||
return StrUtil.toCamelCase(Convert.toStr(paramsObj.get(GenConstants.TREE_NAME)));
|
||||
}
|
||||
@ -365,8 +365,8 @@ public class VelocityUtils
|
||||
public static int getExpandColumn(GenTable genTable)
|
||||
{
|
||||
String options = genTable.getOptions();
|
||||
Map<String, String> paramsObj = JsonUtils.parseMap(options);
|
||||
String treeName = paramsObj.get(GenConstants.TREE_NAME);
|
||||
Map<String, Object> paramsObj = JsonUtils.parseMap(options);
|
||||
String treeName = Convert.toStr(paramsObj.get(GenConstants.TREE_NAME));
|
||||
int num = 0;
|
||||
for (GenTableColumn column : genTable.getColumns())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user