|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.dsideal.resource.Menu;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.jfinal.kit.Prop;
|
|
|
|
@ -9,6 +10,7 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import com.dsideal.resource.Plugin.YamlProp;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class DatabaseToJsonConverter {
|
|
|
|
@ -23,17 +25,17 @@ public class DatabaseToJsonConverter {
|
|
|
|
|
arp.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Menu rootMenu = fetchMenu(-1); // 从父ID为null开始递归
|
|
|
|
|
List<Menu> rootMenu = fetchMenu(-1); // 从父ID为null开始递归
|
|
|
|
|
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
String json = mapper.writeValueAsString(rootMenu.getChildren());
|
|
|
|
|
String json = mapper.writeValueAsString(rootMenu.getFirst());
|
|
|
|
|
System.out.println(json);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Menu fetchMenu(Integer parentId) {
|
|
|
|
|
private static List<Menu> fetchMenu(Integer parentId) {
|
|
|
|
|
String sql = "select * from t_base_menu where parent_id = ?";
|
|
|
|
|
List<Record> list = Db.find(sql, parentId);
|
|
|
|
|
Menu bigMenu = new Menu();
|
|
|
|
|
List<Menu> res = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (Record rs : list) {
|
|
|
|
|
if (rs == null) return null;
|
|
|
|
@ -58,16 +60,11 @@ public class DatabaseToJsonConverter {
|
|
|
|
|
meta.setAffix(true);
|
|
|
|
|
meta.setKeepAlive(true);
|
|
|
|
|
sMenu.setMeta(meta);
|
|
|
|
|
|
|
|
|
|
// 递归查找子菜单
|
|
|
|
|
Menu childMenu = fetchMenu(rs.getInt("menu_id"));
|
|
|
|
|
if (childMenu != null && bigMenu.getChildren() != null) {
|
|
|
|
|
sMenu.getChildren().add(childMenu);
|
|
|
|
|
}
|
|
|
|
|
if (sMenu != null) {
|
|
|
|
|
bigMenu.getChildren().add(sMenu);
|
|
|
|
|
}
|
|
|
|
|
List<Menu> childMenu = fetchMenu(rs.getInt("menu_id"));
|
|
|
|
|
sMenu.setChildren(childMenu);
|
|
|
|
|
res.add(sMenu);
|
|
|
|
|
}
|
|
|
|
|
return bigMenu;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|