Browse Source

fix: npe when export markdown (#106)

master
vran 3 years ago
committed by GitHub
parent
commit
f03b002598
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      core/src/main/java/com/databasir/core/domain/document/generator/MarkdownDocumentFileGenerator.java

17
core/src/main/java/com/databasir/core/domain/document/generator/MarkdownDocumentFileGenerator.java

@ -93,8 +93,11 @@ public class MarkdownDocumentFileGenerator implements DocumentFileGenerator {
List<List<String>> overviewContent = new ArrayList<>(); List<List<String>> overviewContent = new ArrayList<>();
for (int i = 0; i < doc.getTables().size(); i++) { for (int i = 0; i < doc.getTables().size(); i++) {
TableDocumentResponse table = doc.getTables().get(i); TableDocumentResponse table = doc.getTables().get(i);
overviewContent.add(List.of((i + 1) + "", table.getName(), table.getType(), List<String> row = List.of((i + 1) + "",
table.getComment())); Objects.requireNonNullElse(table.getName(), ""),
Objects.requireNonNullElse(table.getType(), ""),
Objects.requireNonNullElse(table.getComment(), ""));
overviewContent.add(row);
} }
builder.table(List.of("", "表名", "类型", "备注"), overviewContent); builder.table(List.of("", "表名", "类型", "备注"), overviewContent);
} }
@ -115,7 +118,8 @@ public class MarkdownDocumentFileGenerator implements DocumentFileGenerator {
for (int i = 0; i < table.getColumns().size(); i++) { for (int i = 0; i < table.getColumns().size(); i++) {
var column = table.getColumns().get(i); var column = table.getColumns().get(i);
String type; String type;
if (column.getDecimalDigits() == null || column.getDecimalDigits() == 0) { if (column.getDecimalDigits() == null
|| Objects.requireNonNullElse(column.getDecimalDigits(), 0) == 0) {
type = column.getType() + "(" + column.getSize() + ")"; type = column.getType() + "(" + column.getSize() + ")";
} else { } else {
type = column.getType() + "(" + column.getSize() + "," + column.getDecimalDigits() + ")"; type = column.getType() + "(" + column.getSize() + "," + column.getDecimalDigits() + ")";
@ -127,7 +131,7 @@ public class MarkdownDocumentFileGenerator implements DocumentFileGenerator {
column.getNullable(), column.getNullable(),
column.getAutoIncrement(), column.getAutoIncrement(),
columnDefaultValueMapping.apply(column), columnDefaultValueMapping.apply(column),
column.getComment())); Objects.requireNonNullElse(column.getComment(), "")));
} }
builder.table( builder.table(
List.of( List.of(
@ -176,8 +180,9 @@ public class MarkdownDocumentFileGenerator implements DocumentFileGenerator {
TableDocumentResponse.ForeignKeyDocumentResponse fk = table.getForeignKeys().get(i); TableDocumentResponse.ForeignKeyDocumentResponse fk = table.getForeignKeys().get(i);
List<String> item = List.of( List<String> item = List.of(
(i + 1) + "", (i + 1) + "",
fk.getFkName(), fk.getFkColumnName(), Objects.requireNonNullElse(fk.getFkName(), ""), fk.getFkColumnName(),
fk.getPkName(), fk.getPkTableName(), fk.getPkColumnName(), Objects.requireNonNullElse(fk.getPkName(), ""), fk.getPkTableName(),
fk.getPkColumnName(),
fk.getUpdateRule(), fk.getDeleteRule() fk.getUpdateRule(), fk.getDeleteRule()
); );
foreignKeys.add(item); foreignKeys.add(item);

Loading…
Cancel
Save