|
|
|
@ -3,7 +3,10 @@ package com.dsideal.resource.Menu;
|
|
|
|
|
import com.dsideal.resource.Menu.Bean.Menu;
|
|
|
|
|
import com.dsideal.resource.Menu.Bean.Meta;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ArrayNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
|
|
import com.jfinal.kit.Prop;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
@ -14,7 +17,7 @@ import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class DatabaseToJsonConverter {
|
|
|
|
|
public class GetVueMenu {
|
|
|
|
|
public static void main(String[] args) throws JsonProcessingException {
|
|
|
|
|
String configFile = "application_dev.yaml";
|
|
|
|
|
Prop PropKit = new YamlProp(configFile);
|
|
|
|
@ -29,12 +32,40 @@ public class DatabaseToJsonConverter {
|
|
|
|
|
//输出JSON格式
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
String json = mapper.writeValueAsString(rootMenu.getFirst());
|
|
|
|
|
System.out.println(json);
|
|
|
|
|
|
|
|
|
|
//去掉children为空的节点
|
|
|
|
|
JsonNode root = mapper.readTree(json);
|
|
|
|
|
removeEmptyChildren(root);
|
|
|
|
|
String cleanedJson = mapper.writeValueAsString(root);
|
|
|
|
|
System.out.println(cleanedJson);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void removeEmptyChildren(JsonNode node) {
|
|
|
|
|
if (node.isObject()) {
|
|
|
|
|
ObjectNode objectNode = (ObjectNode) node;
|
|
|
|
|
if (objectNode.has("children")) {
|
|
|
|
|
JsonNode children = objectNode.get("children");
|
|
|
|
|
if (children.isArray() && ((ArrayNode) children).isEmpty()) {
|
|
|
|
|
objectNode.remove("children");
|
|
|
|
|
} else if (children.isArray()) {
|
|
|
|
|
ArrayNode arrayNode = (ArrayNode) children;
|
|
|
|
|
for (int i = 0; i < arrayNode.size(); i++) {
|
|
|
|
|
removeEmptyChildren(arrayNode.get(i));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<Menu> fetchMenu(Integer parentId) {
|
|
|
|
|
/**
|
|
|
|
|
* 功能:递归获取菜单
|
|
|
|
|
*
|
|
|
|
|
* @param parent_id
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private static List<Menu> fetchMenu(int parent_id) {
|
|
|
|
|
String sql = "select * from t_base_menu where parent_id = ?";
|
|
|
|
|
List<Record> list = Db.find(sql, parentId);
|
|
|
|
|
List<Record> list = Db.find(sql, parent_id);
|
|
|
|
|
List<Menu> res = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (Record rs : list) {
|