@Test public void exportMarkdownTest() { List<ColumnInfo> columnInfoList1 = new ArrayList<>(); ColumnInfo columnInfo11 = new ColumnInfo(); columnInfo11.setColumnName("id"); columnInfo11.setColumnType("int(11)"); columnInfo11.setAutoIncrement(1); columnInfo11.setNullable("NO"); columnInfo11.setPrimaryKey(1); columnInfo11.setColumnDefault(""); columnInfo11.setColumnComment("自增id"); columnInfoList1.add(columnInfo11); ColumnInfo columnInfo12 = new ColumnInfo(); columnInfo12.setColumnName("name"); columnInfo12.setColumnType("varchar(100)"); columnInfo12.setAutoIncrement(0); columnInfo12.setNullable("NO"); columnInfo12.setPrimaryKey(0); columnInfo12.setColumnDefault(""); columnInfo12.setColumnComment("名称"); columnInfoList1.add(columnInfo12); Mockito.doReturn(columnInfoList1).when(treeService).columnList(Mockito.anyString(), Mockito.anyString()); TableInfo tableInfo1 = new TableInfo(); tableInfo1.setTableName("table"); tableInfo1.setDescription("注释1"); Mockito.doReturn(tableInfo1).when(treeService).oneTable("db", "table"); TableInfo tableInfo2 = new TableInfo(); tableInfo2.setTableName("table2"); tableInfo2.setDescription("注释2"); Mockito.doReturn(tableInfo2).when(treeService).oneTable("db", "table2"); String result = tableExportService.exportMarkdown("db", Arrays.asList("table", "table2")); assertEquals("\n" + "\n" + "## table: 注释1\n" + "序号|字段名|类型|自增|可空|主键|默认值|注释\n" + "---|---|---|---|---|---|---|---\n" + "0|id|int(11)|1|NO|1||自增id\n" + "1|name|varchar(100)|0|NO|0||名称\n" + "\n" + "## table2: 注释2\n" + "序号|字段名|类型|自增|可空|主键|默认值|注释\n" + "---|---|---|---|---|---|---|---\n" + "0|id|int(11)|1|NO|1||自增id\n" + "1|name|varchar(100)|0|NO|0||名称", result); }
@Override public String exportMarkdown(String dbName, List<String> tableList) { StringBuilder markdownBuilder = new StringBuilder(); for (String table : tableList) { TableInfo tableInfo = treeService.oneTable(dbName, table); List<ColumnInfo> columnInfoList = treeService.columnList(dbName, table); markdownBuilder.append("\n\n").append("## ").append(table).append(": ").append(tableInfo.getDescription()).append("\n"); markdownBuilder.append("序号|字段名|类型|自增|可空|主键|默认值|注释").append("\n") .append("---|---|---|---|---|---|---|---"); for (int i = 0; i < columnInfoList.size(); i++) { ColumnInfo columnInfo = columnInfoList.get(i); markdownBuilder.append("\n").append(i).append("|") .append(columnInfo.getColumnName()).append("|") .append(columnInfo.getColumnType()).append("|") .append(columnInfo.getAutoIncrement()).append("|") .append(columnInfo.getNullable()).append("|") .append(columnInfo.getPrimaryKey()).append("|") .append(columnInfo.getColumnDefault() == null ? "" : columnInfo.getColumnDefault()).append("|") .append(columnInfo.getColumnComment()); } } return markdownBuilder.toString(); }
TableExportService implements ITableExportService { @Override public String exportMarkdown(String dbName, List<String> tableList) { StringBuilder markdownBuilder = new StringBuilder(); for (String table : tableList) { TableInfo tableInfo = treeService.oneTable(dbName, table); List<ColumnInfo> columnInfoList = treeService.columnList(dbName, table); markdownBuilder.append("\n\n").append("## ").append(table).append(": ").append(tableInfo.getDescription()).append("\n"); markdownBuilder.append("序号|字段名|类型|自增|可空|主键|默认值|注释").append("\n") .append("---|---|---|---|---|---|---|---"); for (int i = 0; i < columnInfoList.size(); i++) { ColumnInfo columnInfo = columnInfoList.get(i); markdownBuilder.append("\n").append(i).append("|") .append(columnInfo.getColumnName()).append("|") .append(columnInfo.getColumnType()).append("|") .append(columnInfo.getAutoIncrement()).append("|") .append(columnInfo.getNullable()).append("|") .append(columnInfo.getPrimaryKey()).append("|") .append(columnInfo.getColumnDefault() == null ? "" : columnInfo.getColumnDefault()).append("|") .append(columnInfo.getColumnComment()); } } return markdownBuilder.toString(); } }
TableExportService implements ITableExportService { @Override public String exportMarkdown(String dbName, List<String> tableList) { StringBuilder markdownBuilder = new StringBuilder(); for (String table : tableList) { TableInfo tableInfo = treeService.oneTable(dbName, table); List<ColumnInfo> columnInfoList = treeService.columnList(dbName, table); markdownBuilder.append("\n\n").append("## ").append(table).append(": ").append(tableInfo.getDescription()).append("\n"); markdownBuilder.append("序号|字段名|类型|自增|可空|主键|默认值|注释").append("\n") .append("---|---|---|---|---|---|---|---"); for (int i = 0; i < columnInfoList.size(); i++) { ColumnInfo columnInfo = columnInfoList.get(i); markdownBuilder.append("\n").append(i).append("|") .append(columnInfo.getColumnName()).append("|") .append(columnInfo.getColumnType()).append("|") .append(columnInfo.getAutoIncrement()).append("|") .append(columnInfo.getNullable()).append("|") .append(columnInfo.getPrimaryKey()).append("|") .append(columnInfo.getColumnDefault() == null ? "" : columnInfo.getColumnDefault()).append("|") .append(columnInfo.getColumnComment()); } } return markdownBuilder.toString(); }  }
TableExportService implements ITableExportService { @Override public String exportMarkdown(String dbName, List<String> tableList) { StringBuilder markdownBuilder = new StringBuilder(); for (String table : tableList) { TableInfo tableInfo = treeService.oneTable(dbName, table); List<ColumnInfo> columnInfoList = treeService.columnList(dbName, table); markdownBuilder.append("\n\n").append("## ").append(table).append(": ").append(tableInfo.getDescription()).append("\n"); markdownBuilder.append("序号|字段名|类型|自增|可空|主键|默认值|注释").append("\n") .append("---|---|---|---|---|---|---|---"); for (int i = 0; i < columnInfoList.size(); i++) { ColumnInfo columnInfo = columnInfoList.get(i); markdownBuilder.append("\n").append(i).append("|") .append(columnInfo.getColumnName()).append("|") .append(columnInfo.getColumnType()).append("|") .append(columnInfo.getAutoIncrement()).append("|") .append(columnInfo.getNullable()).append("|") .append(columnInfo.getPrimaryKey()).append("|") .append(columnInfo.getColumnDefault() == null ? "" : columnInfo.getColumnDefault()).append("|") .append(columnInfo.getColumnComment()); } } return markdownBuilder.toString(); }  @Override String exportMarkdown(String dbName, List<String> tableList); }
TableExportService implements ITableExportService { @Override public String exportMarkdown(String dbName, List<String> tableList) { StringBuilder markdownBuilder = new StringBuilder(); for (String table : tableList) { TableInfo tableInfo = treeService.oneTable(dbName, table); List<ColumnInfo> columnInfoList = treeService.columnList(dbName, table); markdownBuilder.append("\n\n").append("## ").append(table).append(": ").append(tableInfo.getDescription()).append("\n"); markdownBuilder.append("序号|字段名|类型|自增|可空|主键|默认值|注释").append("\n") .append("---|---|---|---|---|---|---|---"); for (int i = 0; i < columnInfoList.size(); i++) { ColumnInfo columnInfo = columnInfoList.get(i); markdownBuilder.append("\n").append(i).append("|") .append(columnInfo.getColumnName()).append("|") .append(columnInfo.getColumnType()).append("|") .append(columnInfo.getAutoIncrement()).append("|") .append(columnInfo.getNullable()).append("|") .append(columnInfo.getPrimaryKey()).append("|") .append(columnInfo.getColumnDefault() == null ? "" : columnInfo.getColumnDefault()).append("|") .append(columnInfo.getColumnComment()); } } return markdownBuilder.toString(); }  @Override String exportMarkdown(String dbName, List<String> tableList);  }