抽取重复代码到一个方法并修改方法为private级别

pull/93/head
wangjianlong 2019-05-27 14:41:37 +08:00
parent ba55256630
commit 74834fd24e
1 changed files with 135 additions and 140 deletions

View File

@ -60,12 +60,7 @@ public class GenServiceImpl implements IGenService
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
// 查询表信息
TableInfo table = genMapper.selectTableByName(tableName);
// 查询列信息
List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
// 生成代码
generatorCode(table, columns, zip);
generatorCode(tableName, zip);
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
@ -83,22 +78,22 @@ public class GenServiceImpl implements IGenService
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames)
{
// 查询表信息
TableInfo table = genMapper.selectTableByName(tableName);
// 查询列信息
List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
// 生成代码
generatorCode(table, columns, zip);
generatorCode(tableName, zip);
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
/**
*
*
*/
public void generatorCode(TableInfo table, List<ColumnInfo> columns, ZipOutputStream zip)
private void generatorCode(String tableName, ZipOutputStream zip)
{
// 查询表信息
TableInfo table = genMapper.selectTableByName(tableName);
// 查询列信息
List<ColumnInfo> columns = genMapper.selectTableColumnsByName(tableName);
// 表名转换成Java属性名
String className = GenUtils.tableToJava(table.getTableName());
table.setClassName(className);