一、sql語句css
<!--查看數據字典 --> <select id="queryDbDictionary" parameterType="string" resultType="DbDictionary"> SELECT a.TABLE_SCHEMA as tableSchema, a.TABLE_NAME as tableName, a.COLUMN_NAME as columnName, a.ORDINAL_POSITION as ordinalPosition, a.COLUMN_DEFAULT as columnDefault, a.IS_NULLABLE as isNullable, a.COLUMN_TYPE as columnType, a.COLUMN_COMMENT as columnComment, a.COLUMN_KEY as columnKey, a.EXTRA as extra, b.TABLE_COMMENT as tableComment from information_schema.COLUMNS a LEFT JOIN information_schema.TABLES b ON a.TABLE_NAME=b.TABLE_NAME where a.TABLE_SCHEMA=#{value} ORDER BY b.TABLE_NAME </select>
二、實體html
/** * 數據字典模型類 * Created by fuguangli on 2016/12/7. */ @Data @EqualsAndHashCode(callSuper = false) public class DbDictionary implements Serializable { /** * */ private static final long serialVersionUID = -7536298200802665693L; private String tableSchema; //數據庫名 private String tableName; //代表 private String ordinalPosition; //序號 private String columnName; //字段名 private String columnType; //字段類型 private String columnDefault; //字段默認 private String isNullable; //能否空 private String extra; //其餘 private String columnKey; //主鍵約束 private String columnComment; //字段註釋 private String tableComment; //表註釋 }
三、servicejava
@Override public Map<String, Object> queryDbDictionary(String tableSchema) { List<DbDictionary> dbDictionaries = qyInteriorDao.queryDbDictionary(tableSchema); System.err.println(dbDictionaries.toString()); Map<String, Object> map = null; String schema = tableSchema; // 數據庫名稱 if (dbDictionaries != null && dbDictionaries.size() > 0) { map = new HashMap<>(); List<DbDictionary> columns = null; Map<String, List<DbDictionary>> tables = null; tables = new TreeMap<>(); for (DbDictionary db : dbDictionaries) { columns = new LinkedList<>(); String tableName = db.getTableName(); if (tables.containsKey(tableName)) { tables.get(tableName).add(db); } else { columns.add(db); tables.put(tableName, columns); } } map.put("schema", schema); map.put("tables", tables); System.err.println(map.toString()); return map; } return null; }
四、jspsql
<%-- Created by IntelliJ IDEA. User: fuguangli Date: 2016/12/7 Time: 11:36 To change this template use File | Settings | File Templates. 用於獲取數據字典 --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ include file="/base.jsp" %> <html> <head> <title>${map.schema} 數據字典</title> <link href="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container"> <h1 style="text-align:center;">${map.schema} 數據字典</h1> <c:forEach items="${map.tables}" varStatus="status" var="table"> <h3>${table.key} 備註:${table.value[0].tableComment}</h3> <table class="table table-hover table-bordered table-condensed"> <thead> <tr> <th>序號</th> <th>字段名</th> <th>數據類型</th> <th>默認值</th> <th>容許非空</th> <th>其餘選項</th> <th>主鍵約束</th> <th>備註</th> </tr> </thead> <tbody> <c:forEach items="${table.value}" var="columns" varStatus="s2"> <tr> <td>${columns.ordinalPosition}</td> <td>${columns.columnName}</td> <td>${columns.columnType}</td> <td>${columns.columnDefault}</td> <td>${columns.isNullable}</td> <td>${columns.extra}</td> <td>${columns.columnKey}</td> <td>${columns.columnComment}</td> </tr> </c:forEach> </tbody> </table> </c:forEach> </div> </body> </html>
五、最後的樣子數據庫