From 7fb34b26e7391b0300bd89d0d5153029d2eba648 Mon Sep 17 00:00:00 2001 From: zhangjiajia <420154195@qq.com> Date: Thu, 27 Jun 2019 18:31:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=94=9F=E6=88=90=E7=9A=84entity?= =?UTF-8?q?=E4=B8=AD=E5=A2=9E=E5=8A=A0swagger=E6=8E=A5=E5=8F=A3=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E4=B8=AD=E5=B1=9E=E6=80=A7=E8=AF=B4=E6=98=8E=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pig4cloud/pigx/codegen/entity/ColumnEntity.java | 12 ++++++++++++ .../com/pig4cloud/pigx/codegen/util/GenUtils.java | 12 ++++++++++-- .../src/main/resources/generator.properties | 3 +++ .../src/main/resources/mapper/SysGeneratorMapper.xml | 2 +- .../src/main/resources/template/Entity.java.vm | 1 + 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java index 445a307b2..9f783d733 100755 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/entity/ColumnEntity.java @@ -55,4 +55,16 @@ public class ColumnEntity { * 其他信息 */ private String extra; + /** + * 字段类型 + */ + private String columnType; + /** + * 是否可以为空 + */ + private Boolean nullable; + /** + * 是否隐藏 + */ + private Boolean hidden; } diff --git a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java index 9859c459c..8bc51278a 100644 --- a/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java +++ b/pigx-visual/pigx-codegen/src/main/java/com/pig4cloud/pigx/codegen/util/GenUtils.java @@ -111,7 +111,8 @@ public class GenUtils { String className = tableToJava(tableEntity.getTableName(), tablePrefix); tableEntity.setCaseClassName(className); tableEntity.setLowerClassName(StringUtils.uncapitalize(className)); - + //获取需要在swagger文档中隐藏的属性字段 + List hiddenColumns = config.getList("hiddenColumn"); //列信息 List columnList = new ArrayList<>(); for (Map column : columns) { @@ -120,7 +121,14 @@ public class GenUtils { columnEntity.setDataType(column.get("dataType")); columnEntity.setComments(column.get("columnComment")); columnEntity.setExtra(column.get("extra")); - + columnEntity.setNullable("NO".equals(column.get("isNullable"))); + columnEntity.setColumnType(column.get("columnType")); + //隐藏不需要的在接口文档中展示的字段 + if(hiddenColumns.contains(column.get("columnName"))){ + columnEntity.setHidden(Boolean.TRUE); + }else{ + columnEntity.setHidden(Boolean.FALSE); + } //列名转换成Java属性名 String attrName = columnToJava(columnEntity.getColumnName()); columnEntity.setCaseAttrName(attrName); diff --git a/pigx-visual/pigx-codegen/src/main/resources/generator.properties b/pigx-visual/pigx-codegen/src/main/resources/generator.properties index 316e822be..082cd463e 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/generator.properties +++ b/pigx-visual/pigx-codegen/src/main/resources/generator.properties @@ -32,3 +32,6 @@ longtext=String date=LocalDateTime datetime=LocalDateTime timestamp=LocalDateTime + +# hidden columns in Swagger Models +hiddenColumn=gmt_create,gmt_modified,tenant_id diff --git a/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml b/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml index 256b917b9..50eb0b8c4 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml +++ b/pigx-visual/pigx-codegen/src/main/resources/mapper/SysGeneratorMapper.xml @@ -17,7 +17,7 @@ diff --git a/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm b/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm index 93610e4c4..0acf6b2e8 100755 --- a/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm +++ b/pigx-visual/pigx-codegen/src/main/resources/template/Entity.java.vm @@ -49,6 +49,7 @@ private static final long serialVersionUID = 1L; #if($column.columnName == $pk.columnName) @TableId #end + @ApiModelProperty(value="$column.comments"#if($column.nullable),required=$column.nullable#end#if($column.hidden),hidden=$column.hidden#end) private $column.attrType $column.lowerAttrName; #end