在生成的entity中增加swagger接口文档中属性说明注解

This commit is contained in:
zhangjiajia committed 2019-06-27 18:31:34 +08:00
1 parent a002299c3e
commit 7fb34b26e7
5 files changed
+27 -3

No files matched your search

@@ -55,4 +55,16 @@ public class ColumnEntity {
* 其他信息
*/
private String extra;
/**
* 字段类型
*/
private String columnType;
/**
* 是否可以为空
*/
private Boolean nullable;
/**
* 是否隐藏
*/
private Boolean hidden;
}
@@ -111,7 +111,8 @@ public class GenUtils {
String className = tableToJava(tableEntity.getTableName(), tablePrefix);
tableEntity.setCaseClassName(className);
tableEntity.setLowerClassName(StringUtils.uncapitalize(className));
//获取需要在swagger文档中隐藏的属性字段
List<Object> hiddenColumns = config.getList("hiddenColumn");
//列信息
List<ColumnEntity> columnList = new ArrayList<>();
for (Map<String, String> 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);
@@ -32,3 +32,6 @@ longtext=String
date=LocalDateTime
datetime=LocalDateTime
timestamp=LocalDateTime
# hidden columns in Swagger Models
hiddenColumn=gmt_create,gmt_modified,tenant_id
@@ -17,7 +17,7 @@
</select>
<select id="queryColumns" resultType="map">
select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra from information_schema.columns
select column_name columnName, data_type dataType, column_comment columnComment, column_key columnKey, extra ,is_nullable as isNullable,column_type as columnType from information_schema.columns
where table_name = #{tableName} and table_schema = (select database()) order by ordinal_position
</select>
</mapper>
@@ -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