From 5ae1fb63ddcb03730794f07682854e4711ee73db Mon Sep 17 00:00:00 2001 From: 15858193327 Date: Thu, 22 Oct 2020 02:48:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(code-gen):=20=E6=B7=BB=E5=8A=A0JPA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dynamicConfig/README.MD | 18 ++++++++- .../controller/GeneratorController.java | 5 +-- .../generator/dao/SysGeneratorDao.java | 6 +++ .../generator/dao/SysGeneratorDao.xml | 4 ++ .../shoulder/generator/model/TableEntity.java | 1 + .../service/SysGeneratorService.java | 1 + .../service/impl/SysGeneratorServiceImpl.java | 23 ++++++++++- .../shoulder/generator/utils/GenUtils.java | 39 ++++++++++++------ .../src/main/resources/generator.properties | 2 +- .../resources/template/Controller.java.vm | 40 +++++++++++-------- .../main/resources/template/Entity.java.vm | 4 +- .../main/resources/template/JpaEntity.java.vm | 38 ++++++++++++++++++ .../resources/template/JpaRepository.java.vm | 35 ++++++++++++++++ .../template/{Dao.java.vm => Mapper.java.vm} | 6 +-- .../template/{Dao.xml.vm => Mapper.xml.vm} | 4 +- .../resources/template/ServiceImpl.java.vm | 22 +++++----- shoulder-platform-common/README.md | 4 +- shoulder-system-center/system-modules/pom.xml | 2 +- 18 files changed, 198 insertions(+), 56 deletions(-) create mode 100644 shoulder-generator/src/main/resources/template/JpaEntity.java.vm create mode 100644 shoulder-generator/src/main/resources/template/JpaRepository.java.vm rename shoulder-generator/src/main/resources/template/{Dao.java.vm => Mapper.java.vm} (82%) rename shoulder-generator/src/main/resources/template/{Dao.xml.vm => Mapper.xml.vm} (92%) diff --git a/dynamicConfig/README.MD b/dynamicConfig/README.MD index 9ab55be..84e4b39 100644 --- a/dynamicConfig/README.MD +++ b/dynamicConfig/README.MD @@ -1 +1,17 @@ -maven 多环境打包 配置信息自动切换 \ No newline at end of file +## `Maven` 多环境打包 + +配置信息自动切换 + +## 安全 - 敏感配置项加密 + +配置文件中包含了中间件密码、第三方应用密钥等敏感信息,直接以明文方式存储并不安全,故需要加密。 + +由于我们使用了配置中心,故只需要保证系统与配置中心的通信安全即可,我们采用了 `Nacos`,有以下几种方案可供参考: + +* 将 `Nacos-Server` 与应用部署在同一个局域网中,不暴露于互联网。 + +* `Nacos-Server` 可以支持 `https` 对数据进行加密的,对 `Nacos-Server` 进行改造,使其支持 `https`。 + +* 通过 `nginx` 间接访问保护,`nginx` 不仅仅可以提供 `https`,还可以提供 `Basic Authentication`、`IP白名单` 等安全方式。 + +如果不使用注册中心,可以使用 `jasypt` 等方式来将敏感信息脱敏处理。 diff --git a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/controller/GeneratorController.java b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/controller/GeneratorController.java index 4fc27e8..607ec7b 100644 --- a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/controller/GeneratorController.java +++ b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/controller/GeneratorController.java @@ -43,7 +43,7 @@ public class GeneratorController { /** * 生成代码 * web 中不需要主动关闭流 - * http://localhost:8080/generator/code?tables=tb_shop + * http://localhost:8080/generator/code?tables=* */ @RequestMapping("/code") public void code(String tables, HttpServletResponse response) throws IOException { @@ -51,9 +51,8 @@ public class GeneratorController { if (StringUtils.isEmpty(tables)) { throw new IllegalArgumentException("tableName can't be empty"); } - response.reset(); - byte[] data = sysGeneratorService.generatorCode(tables.split(","), response.getOutputStream()); + byte[] data = "*".equals(tables) ? sysGeneratorService.generatorCode(response.getOutputStream()) :sysGeneratorService.generatorCode(tables.split(","), response.getOutputStream()); if (data != null && data.length > 0) { /* // file out put stream 必须及时关闭 diff --git a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.java b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.java index af290c8..ae21dd5 100644 --- a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.java +++ b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.java @@ -1,6 +1,7 @@ package cn.itlym.shoulder.generator.dao; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Repository; import java.util.List; @@ -21,4 +22,9 @@ public interface SysGeneratorDao { List> queryColumns(String tableName); + @Select("select * from information_schema.TABLES where TABLE_SCHEMA=(select database())") + List> listTable(); + + @Select("select TABLE_NAME from information_schema.TABLES where TABLE_SCHEMA=(select database())") + List listTableNames(); } diff --git a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.xml b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.xml index 19c8288..6bbbe47 100644 --- a/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.xml +++ b/shoulder-generator/src/main/java/cn/itlym/shoulder/generator/dao/SysGeneratorDao.xml @@ -19,6 +19,10 @@ + +