作者 钟来

添加指定数据库生成

... ... @@ -111,11 +111,11 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasPermi('tool:gen:import')")
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable")
public AjaxResult importTableSave(String tables)
public AjaxResult importTableSave(String databaseName,String tables)
{
String[] tableNames = Convert.toStrArray(tables);
// 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
List<GenTable> tableList = genTableService.selectDbTableListByNames(databaseName,tableNames);
genTableService.importGenTable(tableList, SecurityUtils.getUsername());
return success();
}
... ... @@ -126,7 +126,7 @@ public class GenController extends BaseController
@PreAuthorize("@ss.hasRole('admin')")
@Log(title = "创建表", businessType = BusinessType.OTHER)
@PostMapping("/createTable")
public AjaxResult createTableSave(String sql)
public AjaxResult createTableSave(String databaseName,String sql)
{
try
{
... ... @@ -145,7 +145,7 @@ public class GenController extends BaseController
}
}
}
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()]));
List<GenTable> tableList = genTableService.selectDbTableListByNames(databaseName,tableNames.toArray(new String[tableNames.size()]));
String operName = SecurityUtils.getUsername();
genTableService.importGenTable(tableList, operName);
return AjaxResult.success();
... ...
... ... @@ -102,7 +102,18 @@ public class GenTable extends BaseEntity
* 模块路径
*/
private String modlePath;
/**
* 数据库名称
*/
private String databaseName;
public String getDatabaseName() {
return databaseName;
}
public void setDatabaseName(String databaseName) {
this.databaseName = databaseName;
}
public String getModlePath() {
return modlePath;
... ...
... ... @@ -32,7 +32,7 @@ public interface GenTableMapper
* @param tableNames 表名称组
* @return 数据库表集合
*/
public List<GenTable> selectDbTableListByNames(String[] tableNames);
public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames);
/**
* 查询所有表信息
... ...
... ... @@ -94,14 +94,14 @@ public class GenTableServiceImpl implements IGenTableService
/**
* 查询据库列表
*
* @param databaseName 数据库名称
* @param tableNames 表名称组
* @return 数据库表集合
*/
@Override
public List<GenTable> selectDbTableListByNames(String[] tableNames)
public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames)
{
return genTableMapper.selectDbTableListByNames(tableNames);
return genTableMapper.selectDbTableListByNames(databaseName,tableNames);
}
/**
... ...
... ... @@ -33,7 +33,7 @@ public interface IGenTableService
* @param tableNames 表名称组
* @return 数据库表集合
*/
public List<GenTable> selectDbTableListByNames(String[] tableNames);
public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames);
/**
* 查询所有表信息
... ...
... ... @@ -78,9 +78,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = (select database())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
where table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' and table_name NOT IN (select table_name from gen_table)
<if test="databaseName != null and databaseName != ''">
and table_schema = #{databaseName}
</if>
<if test="databaseName == null or databaseName == ''">
and table_schema = (select database())
</if>
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
</if>
... ... @@ -95,14 +99,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if>
order by create_time desc
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%'
<if test="databaseName != null and databaseName != ''">
and table_schema = #{databaseName}
</if>
<if test="databaseName == null or databaseName == ''">
and table_schema = (select database())
</if>
and table_name in
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
<foreach collection="array" item="name" open="(" separator="," close=")">
#{name}
</foreach>
</select>
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
... ...