要验收项目了,要写数据库文档,一大堆表太费劲了,直接生成一个吧,本来想用个别人的轮子,网上看了几个,感觉效果不怎么好,自己动手写一个吧。抽空再把字典表补充进去就OK了
先看效果:
目录快速导航
生成效果
关键代码
try {
String prefixTables = "sys_monitor_db_handle.selectDbTabUsedInfo";
String prefixStructure = "sys_monitor_db_handle.selectDbClumInfo";
String dbname="dbname";
// 获取所有表名
Map<String, Object> paramTables = new HashMap<>();
paramTables.put("tableen", dbname);
String sqlTables = SqlManage.getInstance().getSqlByid(paramTables, prefixTables);
List<Map<String, Object>> tablesList = BaseDao.queryList(sqlTables);
// 生成HTML文档
StringBuilder htmlBuilder = new StringBuilder();
String name="数据库说明文档";
String level="2.0";
String auth="wheart.cn";
String date=ToolDateTime.getYYYYmmdd();
generateHtmlHeader(htmlBuilder,name,level,auth,date);
StringBuilder navBuilder = new StringBuilder();
navBuilder.append("<nav><h2 id='mulu'>目录</h2><ul>\n");
for (Map<String, Object> tableInfo : tablesList) {
String tableName = (String) tableInfo.get("tableen");
String tableNamecn = tableInfo.get("tabcn")+"";
generateHtmlnav(navBuilder,tableName,tableNamecn);
Map<String, Object> paramStructure = new HashMap<>();
paramStructure.put("tableen", tableName);
paramStructure.put("dbname", dbname);
String sqlStructure = SqlManage.getInstance().getSqlByid(paramStructure, prefixStructure);
List<Map<String, Object>> columnsList = BaseDao.queryList(sqlStructure);
generateHtmlTable(htmlBuilder, tableName, tableNamecn, columnsList);
}
navBuilder.append("</ul></nav>\n"); // 结束导航列表和导航部分
String conDivStart = "<div class=\"con\">";
int conDivIndexStart = htmlBuilder.indexOf(conDivStart);
htmlBuilder.insert(conDivIndexStart + conDivStart.length(), navBuilder.toString());
generateHtmlFooter(htmlBuilder);
writeHtmlToFile(htmlBuilder.toString(), name+"_"+auth+"_"+level+"_"+date+".html");
标签:java,String,tableName,navBuilder,htmlBuilder,一键,html,new,dbname
From: https://blog.csdn.net/a913222/article/details/141575547