正在显示
6 个修改的文件
包含
38 行增加
和
17 行删除
| @@ -111,11 +111,11 @@ public class GenController extends BaseController | @@ -111,11 +111,11 @@ public class GenController extends BaseController | ||
| 111 | @PreAuthorize("@ss.hasPermi('tool:gen:import')") | 111 | @PreAuthorize("@ss.hasPermi('tool:gen:import')") |
| 112 | @Log(title = "代码生成", businessType = BusinessType.IMPORT) | 112 | @Log(title = "代码生成", businessType = BusinessType.IMPORT) |
| 113 | @PostMapping("/importTable") | 113 | @PostMapping("/importTable") |
| 114 | - public AjaxResult importTableSave(String tables) | 114 | + public AjaxResult importTableSave(String databaseName,String tables) |
| 115 | { | 115 | { |
| 116 | String[] tableNames = Convert.toStrArray(tables); | 116 | String[] tableNames = Convert.toStrArray(tables); |
| 117 | // 查询表信息 | 117 | // 查询表信息 |
| 118 | - List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | 118 | + List<GenTable> tableList = genTableService.selectDbTableListByNames(databaseName,tableNames); |
| 119 | genTableService.importGenTable(tableList, SecurityUtils.getUsername()); | 119 | genTableService.importGenTable(tableList, SecurityUtils.getUsername()); |
| 120 | return success(); | 120 | return success(); |
| 121 | } | 121 | } |
| @@ -126,7 +126,7 @@ public class GenController extends BaseController | @@ -126,7 +126,7 @@ public class GenController extends BaseController | ||
| 126 | @PreAuthorize("@ss.hasRole('admin')") | 126 | @PreAuthorize("@ss.hasRole('admin')") |
| 127 | @Log(title = "创建表", businessType = BusinessType.OTHER) | 127 | @Log(title = "创建表", businessType = BusinessType.OTHER) |
| 128 | @PostMapping("/createTable") | 128 | @PostMapping("/createTable") |
| 129 | - public AjaxResult createTableSave(String sql) | 129 | + public AjaxResult createTableSave(String databaseName,String sql) |
| 130 | { | 130 | { |
| 131 | try | 131 | try |
| 132 | { | 132 | { |
| @@ -145,7 +145,7 @@ public class GenController extends BaseController | @@ -145,7 +145,7 @@ public class GenController extends BaseController | ||
| 145 | } | 145 | } |
| 146 | } | 146 | } |
| 147 | } | 147 | } |
| 148 | - List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames.toArray(new String[tableNames.size()])); | 148 | + List<GenTable> tableList = genTableService.selectDbTableListByNames(databaseName,tableNames.toArray(new String[tableNames.size()])); |
| 149 | String operName = SecurityUtils.getUsername(); | 149 | String operName = SecurityUtils.getUsername(); |
| 150 | genTableService.importGenTable(tableList, operName); | 150 | genTableService.importGenTable(tableList, operName); |
| 151 | return AjaxResult.success(); | 151 | return AjaxResult.success(); |
| @@ -102,7 +102,18 @@ public class GenTable extends BaseEntity | @@ -102,7 +102,18 @@ public class GenTable extends BaseEntity | ||
| 102 | * 模块路径 | 102 | * 模块路径 |
| 103 | */ | 103 | */ |
| 104 | private String modlePath; | 104 | private String modlePath; |
| 105 | + /** | ||
| 106 | + * 数据库名称 | ||
| 107 | + */ | ||
| 108 | + private String databaseName; | ||
| 105 | 109 | ||
| 110 | + public String getDatabaseName() { | ||
| 111 | + return databaseName; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setDatabaseName(String databaseName) { | ||
| 115 | + this.databaseName = databaseName; | ||
| 116 | + } | ||
| 106 | 117 | ||
| 107 | public String getModlePath() { | 118 | public String getModlePath() { |
| 108 | return modlePath; | 119 | return modlePath; |
| @@ -32,7 +32,7 @@ public interface GenTableMapper | @@ -32,7 +32,7 @@ public interface GenTableMapper | ||
| 32 | * @param tableNames 表名称组 | 32 | * @param tableNames 表名称组 |
| 33 | * @return 数据库表集合 | 33 | * @return 数据库表集合 |
| 34 | */ | 34 | */ |
| 35 | - public List<GenTable> selectDbTableListByNames(String[] tableNames); | 35 | + public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames); |
| 36 | 36 | ||
| 37 | /** | 37 | /** |
| 38 | * 查询所有表信息 | 38 | * 查询所有表信息 |
| @@ -94,14 +94,14 @@ public class GenTableServiceImpl implements IGenTableService | @@ -94,14 +94,14 @@ public class GenTableServiceImpl implements IGenTableService | ||
| 94 | 94 | ||
| 95 | /** | 95 | /** |
| 96 | * 查询据库列表 | 96 | * 查询据库列表 |
| 97 | - * | 97 | + * @param databaseName 数据库名称 |
| 98 | * @param tableNames 表名称组 | 98 | * @param tableNames 表名称组 |
| 99 | * @return 数据库表集合 | 99 | * @return 数据库表集合 |
| 100 | */ | 100 | */ |
| 101 | @Override | 101 | @Override |
| 102 | - public List<GenTable> selectDbTableListByNames(String[] tableNames) | 102 | + public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames) |
| 103 | { | 103 | { |
| 104 | - return genTableMapper.selectDbTableListByNames(tableNames); | 104 | + return genTableMapper.selectDbTableListByNames(databaseName,tableNames); |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | /** | 107 | /** |
| @@ -33,7 +33,7 @@ public interface IGenTableService | @@ -33,7 +33,7 @@ public interface IGenTableService | ||
| 33 | * @param tableNames 表名称组 | 33 | * @param tableNames 表名称组 |
| 34 | * @return 数据库表集合 | 34 | * @return 数据库表集合 |
| 35 | */ | 35 | */ |
| 36 | - public List<GenTable> selectDbTableListByNames(String[] tableNames); | 36 | + public List<GenTable> selectDbTableListByNames(String databaseName,String[] tableNames); |
| 37 | 37 | ||
| 38 | /** | 38 | /** |
| 39 | * 查询所有表信息 | 39 | * 查询所有表信息 |
| @@ -78,9 +78,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -78,9 +78,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 78 | 78 | ||
| 79 | <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> | 79 | <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> |
| 80 | select table_name, table_comment, create_time, update_time from information_schema.tables | 80 | select table_name, table_comment, create_time, update_time from information_schema.tables |
| 81 | - where table_schema = (select database()) | ||
| 82 | - AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' | ||
| 83 | - AND table_name NOT IN (select table_name from gen_table) | 81 | + where table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' and table_name NOT IN (select table_name from gen_table) |
| 82 | + <if test="databaseName != null and databaseName != ''"> | ||
| 83 | + and table_schema = #{databaseName} | ||
| 84 | + </if> | ||
| 85 | + <if test="databaseName == null or databaseName == ''"> | ||
| 86 | + and table_schema = (select database()) | ||
| 87 | + </if> | ||
| 84 | <if test="tableName != null and tableName != ''"> | 88 | <if test="tableName != null and tableName != ''"> |
| 85 | AND lower(table_name) like lower(concat('%', #{tableName}, '%')) | 89 | AND lower(table_name) like lower(concat('%', #{tableName}, '%')) |
| 86 | </if> | 90 | </if> |
| @@ -95,14 +99,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -95,14 +99,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 95 | </if> | 99 | </if> |
| 96 | order by create_time desc | 100 | order by create_time desc |
| 97 | </select> | 101 | </select> |
| 98 | - | 102 | + |
| 99 | <select id="selectDbTableListByNames" resultMap="GenTableResult"> | 103 | <select id="selectDbTableListByNames" resultMap="GenTableResult"> |
| 100 | select table_name, table_comment, create_time, update_time from information_schema.tables | 104 | select table_name, table_comment, create_time, update_time from information_schema.tables |
| 101 | - where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) | 105 | + where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' |
| 106 | + <if test="databaseName != null and databaseName != ''"> | ||
| 107 | + and table_schema = #{databaseName} | ||
| 108 | + </if> | ||
| 109 | + <if test="databaseName == null or databaseName == ''"> | ||
| 110 | + and table_schema = (select database()) | ||
| 111 | + </if> | ||
| 102 | and table_name in | 112 | and table_name in |
| 103 | - <foreach collection="array" item="name" open="(" separator="," close=")"> | ||
| 104 | - #{name} | ||
| 105 | - </foreach> | 113 | + <foreach collection="array" item="name" open="(" separator="," close=")"> |
| 114 | + #{name} | ||
| 115 | + </foreach> | ||
| 106 | </select> | 116 | </select> |
| 107 | 117 | ||
| 108 | <select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> | 118 | <select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> |
-
请 注册 或 登录 后发表评论