parent
660c6b0bbf
commit
a425fabba7
@ -1,7 +1,22 @@
|
||||
package com.dsideal.base.UnitTest;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dsideal.base.Plugin.YamlProp;
|
||||
import com.jfinal.kit.Prop;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
|
||||
public class TestMenu {
|
||||
public static void main(String[] args) {
|
||||
|
||||
String configFile = "application_dev.yaml";
|
||||
Prop PropKit = new YamlProp(configFile);
|
||||
HikariCpPlugin hp = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||||
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||||
hp.start();
|
||||
JSONObject jo=new JSONObject();
|
||||
jo.put("code",200);
|
||||
jo.put("msg","成功");
|
||||
jo.put("data",null);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$/dsRes" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/dsRes/src/main/resource" type="java-resource" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
@ -0,0 +1,73 @@
|
||||
package com.dsideal.resource.Menu;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.jfinal.kit.Prop;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
||||
import com.dsideal.resource.Plugin.YamlProp;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DatabaseToJsonConverter {
|
||||
public static void main(String[] args) throws JsonProcessingException {
|
||||
String configFile = "application_dev.yaml";
|
||||
Prop PropKit = new YamlProp(configFile);
|
||||
HikariCpPlugin hp = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
|
||||
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
|
||||
hp.start();
|
||||
// 配置ActiveRecord插件
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
||||
arp.start();
|
||||
|
||||
|
||||
Menu rootMenu = fetchMenu(-1); // 从父ID为null开始递归
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
String json = mapper.writeValueAsString(rootMenu.getChildren());
|
||||
System.out.println(json);
|
||||
|
||||
}
|
||||
|
||||
private static 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();
|
||||
|
||||
for (Record rs : list) {
|
||||
if (rs == null) return null;
|
||||
|
||||
Menu sMenu = new Menu();
|
||||
String url = rs.getStr("url");
|
||||
sMenu.setPath(url);
|
||||
sMenu.setName(rs.getStr("menu_name"));
|
||||
sMenu.setComponent(url);
|
||||
|
||||
Meta meta = new Meta();
|
||||
meta.setIcon(rs.getStr("icon"));
|
||||
meta.setTitle(rs.getStr("menu_name"));
|
||||
meta.setIsLink("");
|
||||
meta.setHide(false);
|
||||
|
||||
if (rs.get("is_full") == null || rs.getInt("is_full") == 0) {
|
||||
meta.setFull(false);
|
||||
} else {
|
||||
meta.setFull(true);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
return bigMenu;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.dsideal.resource.Menu;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class Menu {
|
||||
private String path;
|
||||
private String name;
|
||||
private String component;
|
||||
private Meta meta;
|
||||
private List<Menu> children=new ArrayList<>();
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.dsideal.resource.Menu;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
class Meta {
|
||||
private String icon;
|
||||
private String title;
|
||||
private String isLink;
|
||||
private boolean isHide;
|
||||
private boolean isFull;
|
||||
private boolean isAffix;
|
||||
private boolean isKeepAlive;
|
||||
}
|
Loading…
Reference in new issue