diff --git a/@run.cmd b/@run.cmd
index e49fe73f..75a69a8d 100644
--- a/@run.cmd
+++ b/@run.cmd
@@ -1,4 +1,3 @@
-java -jar "./generator-web/target/generator-web-3.0.jar"
-pause
-mvn clean compile package
+mvn clean compile
+mvn spring-boot:run
pause
\ No newline at end of file
diff --git a/README.md b/README.md
index 5c136b8d..e01ea413 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# SpringBootCodeGenerator
+# SpringBootCodeGenerator 大狼狗代码生成器
----
又名`Java代码生成器`、`JAVA在线代码生成平台`、`sql转java`、`大狼狗代码生成器`、`mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`

@@ -7,9 +7,13 @@
[](https://github.com/moshowgame/SpringBootCodeGenerator/actions/workflows/maven.yml)
# Author
->powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net)
+>🚀
+Powered by `Moshow郑锴(大狼狗)` 🌟 Might the holy code be with you !
+>
**`CSDN`传送门**️️➡️ [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net)
+>
**微信公众号**➡️`软件开发大百科`
# Description
+本项目是基于 Spring Boot 3 和 Freemarker 的高效代码生成平台,旨在帮助开发者告别繁琐重复的 CRUD 操作,释放双手,让开发更高效。项目支持主流数据库(MySQL、Oracle、PgSQL)和多种模板(JPA、Mybatis、MybatisPlus 等)。
> 🚀 `Spring Boot Code Generator` — a powerful code generation platform built on SpringBoot3 & Freemarker
> ✨ 基于 `SpringBoot3` 和 `Freemarker` 的高效代码生成平台
@@ -34,47 +38,205 @@
> 🙌 Special thanks to BeJSON 前站长 `三叔` 的慧眼与支持,让项目得以脱颖而出,感恩!
-# URL
-
-- 感谢`卡卡`部署在[BEJSON](https://java.bejson.com/generator)上,目前是BeJSON专供的`金牌工具`
-- 感谢`jully.top`部署的副本 [https://jully.top/generator/](https://jully.top/generator/)。
-- 感谢`staticfile`CDN提供稳定、快速、免费的静态文件CDN加速服务(在线版本)
-
-| 访问地址 | http://localhost:1234/generator |
-|:-----------------------|:--------------------------------------------------------------|
-| BEJSON 金牌工具 在线地址 | https://java.bejson.com/generator/ |
-| JSON.CN 金牌工具 在线地址 | https://java.json.cn/generator/ |
-| Jully 在线地址 | https://jully.top/generator/ |
-| NeverWaive 在线地址 | https://codegenerator.neverwaive.cn/ |
-| CSDN BLOG | https://zhengkai.blog.csdn.net |
-| GITEE仓库 | https://gitee.com/moshowgame/SpringBootCodeGenerator/releases |
-| GITHUB仓库 | https://github.com/moshowgame/SpringBootCodeGenerator |
-
-# Tips or Features
-- 支持`DDL SQL`/`INSERT SQL`/`SIMPLE JSON`/`SELECT SQL`(*New)四种生成模式
-- `自动记忆`最近生成的内容,最多保留9个
-- 提供众多`通用模板`,易于使用,复制粘贴加简单修改即可完成CRUD操作
-- 支持`特殊字符`模板(`#`请用`井`代替;`$`请用`¥`代替)
-- `Util集合`提供一些基本对象的使用方法供方便COPY,如对应的CRUD SQL语句、setMap、getMap、get属性等等
-- 关于`类名注释`,可根据`comment=(mysql)`或者`comment on table(pgsql/oracle)`生成
-- 可设置是否`自动引包`(java中的import)及`引入包路径`(java类中的package),建议取消并配合IDEA的自动引包更智能(Settings→Editor→General→Auto Import,勾选Add unambiguous imports on the fly以及Optimize imports on the fly)。
-- 可设置`表名前缀`,例如sys_user前缀为sys_之后可以正确生成user类
-- 可在`applicaltion.yml`中的`OEM.mode`设置`js/css引入模式`为`local`(本地模式,默认)/`CDN`(云CDN模式,在线网站推荐,省流量)
-- OEM信息可以在`applicaltion.yml`中的`OEM`中更改
-- *支持公共js/css的Local/CDN模式切换,方便`本地`或者`工具站`进行部署,可以在`application.yml`的`OEM.Mode=`进行设置,之后请在`header-CDN-v2.html`/`header-local-v2.html`中检查对应js/css配置是否正确。默认为`CDN`模式。对于没有网络的环境请使用`local`模式。
-- 如何判断是否包含Date日期类并引入,搜索`<#assign importDdate = true />`即可找到对应的方法判断和引入
-
-# Branch Detail 分支介绍
-- Master:主力分支,基于SpringBoot3+,需要JDK17+
-- JDK11:兼容分支,版本落后,基于SpringBoot2+,但支持JDK8/JDK11等旧JDK版本[https://github.com/moshowgame/SpringBootCodeGenerator/tree/jdk11]
-
-# 更新预告
-1.计划加入AI来帮忙生成更多样式的模板
-2.改进JSqlParser Engine (Select SQL and Create SQL)
+
+## 功能特性
+
+### 支持多种生成模式
+- DDL SQL 模式:通过建表语句生成代码
+- INSERT SQL 模式:通过插入语句生成代码
+- SELECT SQL 模式:通过查询语句生成代码
+- JSON 模式:通过 JSON 数据生成代码
+
+### 支持多种模板
+- JPA 模板
+- MyBatis 模板
+- MyBatis-Plus 模板
+- BeetlSQL 模板
+- CommonMapper 模板
+- TkMyBatis 模板
+- JDBC Template 模板
+- 前端 UI 模板(Element UI、Bootstrap UI 等)
+
+### 其他特性
+- 自动记忆最近生成的内容
+- 支持特殊字符模板(# 用 井 代替,$ 用 ¥ 代替)
+- 可设置表名前缀
+- 可选择是否自动引包
+- 支持本地/CDN 静态资源引入模式切换
+
+## 技术栈
+
+- Spring Boot 3
+- Freemarker 模板引擎
+- FastJSON2
+- JSqlParser SQL 解析器
+- Lombok 简化代码工具
+
+## 使用说明
+
+### 启动项目
+
+```bash
+# 克隆项目
+git clone https://github.com/moshowgame/SpringBootCodeGenerator.git
+
+# 进入项目目录
+cd SpringBootCodeGenerator
+# 编译项目
+mvn clean compile
+# 运行项目
+mvn spring-boot:run
+```
+
+项目启动后访问 http://localhost:1234/generator
+
+### 添加新模板
+
+1. 在 `resources/templates/code-generator` 目录中找到对应类型
+2. 复制并编写 Freemarker 模板文件(.ftl)
+3. 修改 `template.json` 文件,新增模板信息
+
+### 配置说明
+
+| **配置项** | **说明** | **默认值** |
+|:----|:----|:----|
+| 作者 | authorName | zhengkai.blog.csdn.net |
+| 包名 | packageName | cn.devtools |
+| 返回(成功) | returnUtilSuccess | Return.SUCCESS |
+| 返回(失败) | returnUtilFailure | Return.ERROR |
+| 忽略前缀 | ignorePrefix | sys_ |
+| 输入类型 | dataType | DDL SQL |
+| TinyInt转换 | tinyintTransType | int |
+| 时间类型 | timeTransType | Date |
+| 命名类型 | nameCaseType | CamelCase/驼峰 |
+| 是否包装类型 | isPackageType | true |
+| 是否swaggerUI | isSwagger | false |
+| 是否字段注释 | isComment | true |
+| 是否自动引包 | isAutoImport | |
+| 是否带包路径 | isWithPackage | |
+| 是否Lombok | isLombok | true |
+
+| **模板变量** | **说明** |
+|:-------------|:---------------|
+| tableName | sql中的表名 |
+| className | java类名 |
+| classComment | sql表备注/java类备注 |
+| fieldName | 字段名 |
+| fieldComment | 字段备注 |
+
+
+
+## 重构2025说明
+
+本项目的重构2025在原有基础上进行了现代化重构,优化了项目结构和代码组织,使其更符合现代 Spring Boot 应用的最佳实践。
+
+### 重构亮点
+
+1. **清晰的分层架构**:采用 Controller-Service-DTO-VO 分层设计,各层职责明确
+2. **接口与实现分离**:服务层采用接口与实现分离的设计,便于测试和扩展
+3. **策略模式应用**:使用策略模式处理不同类型的 SQL 解析,易于扩展新的解析方式
+4. **现代化开发规范**:遵循 Spring Boot 和 Java 开发最佳实践
+5. **完善的异常处理**:统一异常处理机制,提供更友好的错误提示
+
+### 重构后项目结构
+
+```
+com.softdev.system.generator
+├── GeneratorApplication.java # 启动类
+├── config # 配置类包
+│ ├── WebMvcConfig.java # MVC配置
+│ └── GlobalExceptionHandler.java # 全局异常处理器
+├── controller # 控制层
+│ ├── PageController.java # 页面跳转控制器
+│ ├── CodeGenController.java # 代码生成相关接口
+│ └── TemplateController.java # 模板相关接口
+├── service # 服务层接口
+│ ├── CodeGenService.java # 代码生成服务接口
+│ ├── TemplateService.java # 模板服务接口
+│ └── parser
+│ ├── SqlParserService.java # SQL解析服务接口
+│ └── JsonParserService.java # JSON解析服务接口
+├── service.impl # 服务实现层
+│ ├── CodeGenServiceImpl.java # 代码生成服务实现
+│ ├── TemplateServiceImpl.java # 模板服务实现
+│ └── parser
+│ ├── SqlParserServiceImpl.java # SQL解析服务实现
+│ └── JsonParserServiceImpl.java # JSON解析服务实现
+├── entity # 实体类
+│ ├── dto
+│ │ ├── ParamInfo.java # 参数信息DTO
+│ │ ├── ClassInfo.java # 类信息DTO
+│ │ └── FieldInfo.java # 字段信息DTO
+│ ├── vo
+│ │ └── ResultVo.java # 统一返回结果VO
+│ └── enums
+│ └── ParserTypeEnum.java # 解析类型枚举
+├── util # 工具类包
+│ ├── FreemarkerUtil.java # Freemarker工具类
+│ ├── StringUtilsPlus.java # 字符串工具类
+│ ├── MapUtil.java # Map工具类
+│ ├── mysqlJavaTypeUtil.java # MySQL类型转换工具类
+│ └── exception
+│ ├── CodeGenException.java # 自定义业务异常
+│ └── SqlParseException.java # SQL解析异常
+└── constant # 常量定义
+ └── CodeGenConstants.java # 代码生成常量(待实现)
+```
+
+### 统一响应格式
+
+所有控制器方法均返回 ResultVo 统一响应对象,保持与前端的兼容性:
+
+```java
+// 成功响应
+ResultVo.ok(data);
+
+// 错误响应
+ResultVo.error(message);
+```
+
+## 重构优势
+
+1. **结构清晰**:通过合理的包结构和分层设计,使项目结构更加清晰易懂
+2. **易于维护**:各层职责明确,便于定位和修复问题
+3. **易于扩展**:采用策略模式等设计模式,便于添加新的功能模块
+4. **现代化**:遵循 Spring Boot 和 Java 的最新最佳实践
+5. **前后端兼容**:保持与现有前端代码的数据交互格式,无缝升级
+
+## 升级问题解决方案
+
+### FastJSON 升级到 FastJSON2
+
+如果在升级 FastJSON 到 FastJSON2 版本时遇到 FastJsonHttpMessageConverter 找不到类问题以及 FastJsonConfig 找不到问题,需要安装以下类库:
+- fastjson2
+- fastjson2-extension
+- fastjson2-extension-spring6
+
+### Spring Boot 3 升级
+
+当项目从 Spring Boot 2.x 升级到 3.x 时,可能会遇到 "java: 程序包 javax.servlet.http 不存在" 问题,这是因为 Spring Boot 3 使用了 Jakarta EE 9+,包名从 javax.* 变更为 jakarta.*。
+
+
+## 版权信息
+
+本项目遵循相关开源协议,欢迎提交问题、分享常用模板,或将你的灵感通过 PR 实现!
+
+## Stargazers over time
+[](https://starchart.cc/moshowgame/SpringBootCodeGenerator)
+
+2025 NewUI V2版本
+
+配置模板
+
+网站流量分析-2024
+
+代码与你,越变越强
+
# Update Logs
| 更新日期 | 更新内容 |
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| 2025.12.07 | 后端重构优化 ;目录结构调整! |
| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL |
| 2025.09.13 | JSqlParser Engine全新升级,目前Select SQL模式相对稳定!
更新SpringBoot等类库版本,修复漏洞
修复CDN问题,切换为staticfile.org |
| 2025.09.06 | 处理建表字段包含 using 字符时无法生成对应字段的情况(感谢@wubiaoo的反馈和@willxiang的PR) |
@@ -147,61 +309,3 @@
| 2018.09.15 | 新增Swagger-UI模板.修复一些命名和导入问题.JPA的Entity默认第一个字段为Id,如果不是请手工修改. |
| 2018.09.13 | 修复字段没有描述以及类型为DATE型导致的问题.新增JPA的Controller模板. |
| 2018.08.31 | 初始化项目.新增JPA系列Entity+Repository模板. |
-
-# ClassInfo/TableInfo
-|名称|说明|
-|:----|:----|
-|packageName|自定义的包名|
-|authorName|自定义的作者名|
-|tableName|sql中的表名|
-|className|java类名|
-|classComment|sql表备注/java类备注|
-|fieldName|字段名|
-|fieldComment|字段备注|
-
-# Options
-|名称|说明|默认值|
-|:----|:----|:----|
-|作者 |authorName|zhengkai.blog.csdn.net|
-|包名 |packageName|cn.devtools|
-|返回(成功)|returnUtilSuccess|Return.SUCCESS|
-|返回(失败)|returnUtilFailure|Return.ERROR|
-|忽略前缀|ignorePrefix |sys_|
-|输入类型 |dataType|DDL SQL|
-|TinyInt转换 |tinyintTransType|int|
-|时间类型 |timeTransType|Date|
-|命名类型 |nameCaseType|CamelCase/驼峰|
-|是否包装类型 |isPackageType|true|
-|是否swaggerUI|isSwagger|false|
-|是否字段注释|isComment|true|
-|是否自动引包|isAutoImport||
-|是否带包路径|isWithPackage||
-|是否Lombok|isLombok|true|
-
-
-# How to add a new template
-1. `resources/templates/code-generator`中找到对应类型
-2. COPY并编写freemarker模板文件`.ftl`
-3. 修改`template.json`文件,新增模板信息,页面可动态加载
-
-# Upgrade Issue Resolution 升级问题解决方案
-- 如果你最近也在升级FastJson到FastJson2版本,而跟我一样也遇到了FastJsonHttpMessageConverter找不到类问题以及FastJsonConfig找不到问题,那么恭喜你,看完本文,安装完fastjson2、fastjson2-extension、fastjson2-extension-spring6这三个类库,你就可以成功使用新版FastJson2了。
- [FastJson2中FastJsonHttpMessageConverter找不到类问题](https://blog.csdn.net/moshowgame/article/details/138013669)
-
-- 当项目从2.7.x的springboot升级到3.0.x的时候,遇到一个问题“java: 程序包javax.servlet.http不存在” 问题:
- [java: 程序包javax.servlet.http不存在](https://zhengkai.blog.csdn.net/article/details/131362304)
-
-- [CSDN【SpringBoot2启示录】专栏](https://blog.csdn.net/moshowgame/category_9274885.html)
-
-## Stargazers over time
-[](https://starchart.cc/moshowgame/SpringBootCodeGenerator)
-
-2025 NewUI V2版本
-
-配置模板
-
-网站流量分析-2024
-
-代码与你,越变越美
-
-
diff --git a/REFACTORING_DOCUMENT.md b/REFACTORING_DOCUMENT.md
new file mode 100644
index 00000000..3c1d5d00
--- /dev/null
+++ b/REFACTORING_DOCUMENT.md
@@ -0,0 +1,217 @@
+# Spring Boot代码生成器项目重构说明文档
+
+## 1. 重构概述
+
+本项目旨在对Spring Boot代码生成器进行现代化重构,使其具有更清晰的架构、更好的可维护性和更强的扩展性。重构遵循现代Spring Boot应用的最佳实践,采用了分层架构设计和多种设计模式。
+
+## 2. 重构目标
+
+1. **清晰的分层架构**:明确Controller、Service、DTO、VO等各层职责
+2. **良好的可扩展性**:通过策略模式处理不同类型的SQL解析
+3. **现代化开发规范**:遵循Spring Boot和Java开发最佳实践
+4. **易于维护**:通过合理的包结构和命名规范提高代码可读性
+5. **前后端兼容性**:保持与现有前端代码的数据交互格式
+
+## 3. 重构后项目结构
+
+```
+com.softdev.system.generator
+├── GeneratorApplication.java # 启动类
+├── config # 配置类包
+│ ├── WebMvcConfig.java # MVC配置
+│ └── GlobalExceptionHandler.java # 全局异常处理器
+├── controller # 控制层
+│ ├── PageController.java # 页面跳转控制器
+│ ├── CodeGenController.java # 代码生成相关接口
+│ └── TemplateController.java # 模板相关接口
+├── service # 服务层接口
+│ ├── CodeGenService.java # 代码生成服务接口
+│ ├── TemplateService.java # 模板服务接口
+│ └── parser
+│ ├── SqlParserService.java # SQL解析服务接口
+│ └── JsonParserService.java # JSON解析服务接口
+├── service.impl # 服务实现层
+│ ├── CodeGenServiceImpl.java # 代码生成服务实现
+│ ├── TemplateServiceImpl.java # 模板服务实现
+│ └── parser
+│ ├── SqlParserServiceImpl.java # SQL解析服务实现
+│ └── JsonParserServiceImpl.java # JSON解析服务实现
+├── entity # 实体类
+│ ├── dto
+│ │ ├── ParamInfo.java # 参数信息DTO
+│ │ ├── ClassInfo.java # 类信息DTO
+│ │ └── FieldInfo.java # 字段信息DTO
+│ ├── vo
+│ │ └── ResultVo.java # 统一返回结果VO
+│ └── enums
+│ └── ParserTypeEnum.java # 解析类型枚举
+├── util # 工具类包
+│ ├── FreemarkerUtil.java # Freemarker工具类
+│ ├── StringUtilsPlus.java # 字符串工具类
+│ ├── MapUtil.java # Map工具类
+│ ├── mysqlJavaTypeUtil.java # MySQL类型转换工具类
+│ └── exception
+│ ├── CodeGenException.java # 自定义业务异常
+│ └── SqlParseException.java # SQL解析异常
+└── constant # 常量定义
+ └── CodeGenConstants.java # 代码生成常量(待实现)
+```
+
+## 4. 各层详细说明
+
+### 4.1 控制层 (Controller)
+
+控制层负责处理HTTP请求,协调业务逻辑并返回结果:
+
+1. **[PageController](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/controller/PageController.java)**:
+ - 处理页面跳转请求
+ - 返回视图页面
+
+2. **[CodeGenController](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/controller/CodeGenController.java)**:
+ - 提供代码生成相关REST API
+ - 处理代码生成请求
+
+3. **[TemplateController](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/controller/TemplateController.java)**:
+ - 提供模板管理相关REST API
+ - 处理模板获取请求
+
+### 4.2 服务层 (Service)
+
+服务层采用接口与实现分离的设计,便于测试和扩展:
+
+1. **接口层**:
+ - [CodeGenService](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/CodeGenService.java): 核心代码生成服务接口
+ - [TemplateService](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/TemplateService.java): 模板管理服务接口
+ - [SqlParserService](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/parser/SqlParserService.java): SQL解析服务接口
+ - [JsonParserService](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/parser/JsonParserService.java): JSON解析服务接口
+
+2. **实现层**:
+ - [CodeGenServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/CodeGenServiceImpl.java): 核心代码生成服务实现
+ - [TemplateServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/TemplateServiceImpl.java): 模板管理服务实现
+ - [SqlParserServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java): SQL解析服务实现
+ - [JsonParserServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/parser/JsonParserServiceImpl.java): JSON解析服务实现
+
+### 4.3 实体层 (Entity)
+
+实体层按照用途分类,避免不同类型对象混用:
+
+1. **DTO (Data Transfer Object)**:
+ - [ParamInfo](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/dto/ParamInfo.java): 参数信息传输对象
+ - [ClassInfo](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/dto/ClassInfo.java): 类信息传输对象
+ - [FieldInfo](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/dto/FieldInfo.java): 字段信息传输对象
+
+2. **VO (View Object)**:
+ - [ResultVo](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/vo/ResultVo.java): 统一返回结果视图对象
+
+3. **Enums**:
+ - [ParserTypeEnum](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/enums/ParserTypeEnum.java): 解析类型枚举
+
+### 4.4 工具层 (Util)
+
+工具层包含各种通用工具类和自定义异常:
+
+1. **工具类**:
+ - [FreemarkerUtil](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java): Freemarker模板处理工具
+ - [StringUtilsPlus](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/StringUtilsPlus.java): 字符串处理工具
+ - [MapUtil](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/MapUtil.java): Map操作工具
+ - [mysqlJavaTypeUtil](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/mysqlJavaTypeUtil.java): MySQL与Java类型映射工具
+
+2. **异常类**:
+ - [CodeGenException](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/exception/CodeGenException.java): 代码生成自定义业务异常
+ - [SqlParseException](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/util/exception/SqlParseException.java): SQL解析异常
+
+## 5. 关键设计模式应用
+
+### 5.1 策略模式
+
+在SQL解析功能中应用策略模式,将不同的解析方式封装成独立的策略类:
+
+1. [SqlParserServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java)中实现了多种SQL解析方法:
+ - `processTableIntoClassInfo`: 默认SQL解析
+ - `generateSelectSqlBySQLPraser`: SELECT SQL解析
+ - `generateCreateSqlBySQLPraser`: CREATE SQL解析
+ - `processTableToClassInfoByRegex`: 正则表达式解析
+ - `processInsertSqlToClassInfo`: INSERT SQL解析
+
+2. [JsonParserServiceImpl](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/service/impl/parser/JsonParserServiceImpl.java)中实现了JSON解析:
+ - `processJsonToClassInfo`: JSON解析
+
+通过策略模式,可以:
+- 避免大量的if-else判断
+- 便于添加新的解析策略
+- 提高代码的可维护性
+
+### 5.2 接口与实现分离
+
+所有服务层都采用接口与实现分离的设计,便于:
+- 单元测试模拟
+- 多种实现方式切换
+- 降低模块间耦合度
+
+## 6. 重要技术实现细节
+
+### 6.1 统一响应格式
+
+所有控制器方法均返回 [ResultVo](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/entity/vo/ResultVo.java) 统一响应对象,保持与前端的兼容性:
+
+```java
+// 成功响应
+ResultVo.ok(data)
+
+// 错误响应
+ResultVo.error(message)
+```
+
+### 6.2 前后端兼容性处理
+
+为了保持与现有前端JavaScript代码的兼容性,在处理响应数据时特别注意了数据结构:
+
+1. 模板获取接口返回数据结构:
+ ```json
+ {
+ "code": 200,
+ "msg": "success",
+ "templates": [...]
+ }
+ ```
+
+2. 代码生成接口返回数据结构:
+ ```json
+ {
+ "code": 200,
+ "msg": "success",
+ "outputJson": {
+ "tableName": "...",
+ "controller": "...",
+ "service": "...",
+ // 其他模板生成的代码
+ }
+ }
+ ```
+
+### 6.3 组件扫描配置
+
+由于服务实现类位于不同的包层级中,已在 [Application](file:///D:/Workspace/Project/SpringBootCodeGenerator/generator-web/src/main/java/com/softdev/system/generator/Application.java) 类中配置了组件扫描路径:
+
+```java
+@SpringBootApplication(scanBasePackages = "com.softdev.system.generator")
+```
+
+确保所有服务实现类都能被正确扫描和注入。
+
+## 7. 重构优势总结
+
+1. **结构清晰**:通过合理的包结构和分层设计,使项目结构更加清晰易懂
+2. **易于维护**:各层职责明确,便于定位和修复问题
+3. **易于扩展**:采用策略模式等设计模式,便于添加新的功能模块
+4. **现代化**:遵循Spring Boot和Java的最新最佳实践
+5. **前后端兼容**:保持与现有前端代码的数据交互格式,无缝升级
+
+## 8. 后续优化建议
+
+1. **添加单元测试**:为各层添加完整的单元测试,确保代码质量
+2. **集成日志系统**:完善日志记录,便于问题排查
+3. **添加缓存机制**:对模板等不常变化的数据添加缓存,提高性能
+4. **完善异常处理**:统一异常处理机制,提供更友好的错误提示
+5. **添加接口文档**:使用Swagger等工具生成接口文档,便于前后端协作
+6. **增加常量定义**:将硬编码的字符串提取为常量,提高可维护性
\ No newline at end of file
diff --git a/generator-web/pom.xml b/generator-web/pom.xml
deleted file mode 100644
index 2dc3742d..00000000
--- a/generator-web/pom.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
- 4.0.0
-
- com.softdev.system
- SpringBootCodeGenerator
- 2023
-
-
- generator-web
- 3.0
- jar
-
-
- UTF-8
- UTF-8
-
-
-
-
-
-
-
-
-
-
-
-
-
- junit
- junit
- test
-
-
-
- org.springframework.boot
- spring-boot-autoconfigure
-
-
- org.projectlombok
- lombok
- 1.18.32
- provided
-
-
-
-
-
-
-
-
- src/main/java
-
- **/*.properties
- **/*.xml
-
- false
-
-
- src/main/resources
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.8.1
-
- true
- javac
- 1.8
- 1.8
- UTF-8
- 1.8
- true
- true
-
-
-
- org.codehaus.plexus
- plexus-compiler-eclipse
- 2.2
-
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
- 3.1.0
-
-
- true
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
- repackage
-
-
-
-
-
-
-
-
diff --git a/generator-web/src/main/java/com/softdev/system/generator/controller/GeneratorController.java b/generator-web/src/main/java/com/softdev/system/generator/controller/GeneratorController.java
deleted file mode 100644
index 44f788f2..00000000
--- a/generator-web/src/main/java/com/softdev/system/generator/controller/GeneratorController.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.softdev.system.generator.controller;
-
-import com.alibaba.fastjson2.JSONArray;
-import com.softdev.system.generator.entity.ClassInfo;
-import com.softdev.system.generator.entity.ParamInfo;
-import com.softdev.system.generator.entity.ReturnT;
-import com.softdev.system.generator.service.GeneratorService;
-import com.softdev.system.generator.util.MapUtil;
-import com.softdev.system.generator.util.TableParseUtil;
-import com.softdev.system.generator.util.ValueUtil;
-import lombok.extern.slf4j.Slf4j;
-import net.sf.jsqlparser.parser.CCJSqlParserUtil;
-import net.sf.jsqlparser.statement.Statement;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.servlet.ModelAndView;
-
-import java.util.Date;
-import java.util.Map;
-
-/**
- * 代码生成控制器
- * @author zhengkai.blog.csdn.net
- */
-@Controller
-@Slf4j
-public class GeneratorController {
- @Autowired
- private ValueUtil valueUtil;
-
- @Autowired
- private GeneratorService generatorService;
-
- @GetMapping("/")
- public ModelAndView defaultPage() {
- return new ModelAndView("newui2").addObject("value",valueUtil);
- }
- @GetMapping("/index")
- public ModelAndView indexPage() {
- return new ModelAndView("newui2").addObject("value",valueUtil);
- }
-
- @RequestMapping("/template/all")
- @ResponseBody
- public ReturnT getAllTemplates() throws Exception {
- String templates = generatorService.getTemplateConfig();
- return ReturnT.ok().put("templates", JSONArray.parseArray(templates));
- }
- @PostMapping("/code/generate")
- @ResponseBody
- public ReturnT generateCode(@RequestBody ParamInfo paramInfo) throws Exception {
- //log.info(JSON.toJSONString(paramInfo.getOptions()));
- if (StringUtils.isEmpty(paramInfo.getTableSql())) {
- return ReturnT.error("表结构信息为空");
- }
- //1.Parse Table Structure 表结构解析
- ClassInfo classInfo = null;
- String dataType = MapUtil.getString(paramInfo.getOptions(),"dataType");
- switch (dataType) {
- case "sql":
- //默认模式:parse DDL table structure from sql
- classInfo = generatorService.processTableIntoClassInfo(paramInfo);
- break;
- case "json":
- //JSON模式:parse field from json string
- classInfo = generatorService.processJsonToClassInfo(paramInfo);
- break;
- case "insert-sql":
- //INSERT SQL模式:parse field from insert sql
- classInfo = generatorService.processInsertSqlToClassInfo(paramInfo);
- break;
- case "sql-regex":
- //正则表达式模式(非完善版本):parse sql by regex
- classInfo = generatorService.processTableToClassInfoByRegex(paramInfo);
- break;
- case "select-sql":
- //SelectSqlBySQLPraser模式:parse select sql by JSqlParser
- classInfo = generatorService.generateSelectSqlBySQLPraser(paramInfo);
- break;
- case "create-sql":
- //CreateSqlBySQLPraser模式:parse create sql by JSqlParser
- classInfo = generatorService.generateCreateSqlBySQLPraser(paramInfo);
- break;
- default:
- //默认模式:parse DDL table structure from sql
- classInfo = generatorService.processTableIntoClassInfo(paramInfo);
- break;
- }
- //2.Set the params 设置表格参数
- paramInfo.getOptions().put("classInfo", classInfo);
- paramInfo.getOptions().put("tableName", classInfo == null ? System.currentTimeMillis() : classInfo.getTableName());
-
- //log the generated table and filed size记录解析了什么表,有多少个字段
- //log.info("generated table :{} , size :{}",classInfo.getTableName(),(classInfo.getFieldList() == null ? "" : classInfo.getFieldList().size()));
-
- //3.generate the code by freemarker templates with parameters . Freemarker根据参数和模板生成代码
- Map result = generatorService.getResultByParams(paramInfo.getOptions());
-// log.info("result {}",result);
- log.info("table:{} - time:{} ", MapUtil.getString(result,"tableName"),new Date());
- return ReturnT.ok().put("outputJson",result);
- }
-
-}
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/ReturnT.java b/generator-web/src/main/java/com/softdev/system/generator/entity/ReturnT.java
deleted file mode 100644
index 5b8b3c62..00000000
--- a/generator-web/src/main/java/com/softdev/system/generator/entity/ReturnT.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.softdev.system.generator.entity;
-
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * common returnT:公共返回封装类
- *
- * @author zhengkai.blog.csdn.net
- */
-@EqualsAndHashCode(callSuper = true)
-@Data
-public class ReturnT extends HashMap {
- private static final long serialVersionUID = 1L;
-
- public ReturnT() {
- put("code", 0);
- put("msg", "success");
- }
-
- public static ReturnT error() {
- return error(500, "未知异常,请联系管理员");
- }
-
- public static ReturnT error(String msg) {
- return error(500, msg);
- }
-
- public static ReturnT error(int code, String msg) {
- ReturnT r = new ReturnT();
- r.put("code", code);
- r.put("msg", msg);
- return r;
- }
- public static ReturnT define(int code, String msg) {
- ReturnT r = new ReturnT();
- r.put("code", code);
- r.put("msg", msg);
- return r;
- }
- public static ReturnT ok(String msg) {
- ReturnT r = new ReturnT();
- r.put("msg", msg);
- return r;
- }
-
- public static ReturnT ok(Map map) {
- ReturnT r = new ReturnT();
- r.putAll(map);
- return r;
- }
-
- public static ReturnT ok() {
- return new ReturnT();
- }
-
- @Override
- public ReturnT put(String key, Object value) {
- super.put(key, value);
- return this;
- }
-}
diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorService.java b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorService.java
deleted file mode 100644
index 5042eb30..00000000
--- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorService.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.softdev.system.generator.service;
-
-import com.softdev.system.generator.entity.ClassInfo;
-import com.softdev.system.generator.entity.ParamInfo;
-import freemarker.template.TemplateException;
-import org.springframework.stereotype.Service;
-
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * GeneratorService
- *
- * @author zhengkai.blog.csdn.net
- */
-public interface GeneratorService {
-
- String getTemplateConfig() throws IOException;
-
- Map getResultByParams(Map params) throws IOException, TemplateException;
- /**
- * 解析Select-SQL生成类信息(JSQLPraser版本)
- * @auther: zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- */
- ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
- ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
- /**
- * 解析DDL-SQL生成类信息
- * @auther: zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- */
- ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception;
- /**
- * 解析JSON生成类信息
- * @auther: zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- */
- ClassInfo processJsonToClassInfo(ParamInfo paramInfo);
- /**
- * 解析DDL SQL生成类信息-正则表达式版本
- * @auther: zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- */
- ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo);
- /**
- * 解析INSERT-SQL生成类信息-正则表达式版本
- * @auther: zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- */
- ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo);
-}
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java b/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java
deleted file mode 100644
index 340bab6a..00000000
--- a/generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.softdev.system.generator.util;
-
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.softdev.system.generator.entity.ClassInfo;
-import com.softdev.system.generator.entity.FieldInfo;
-import com.softdev.system.generator.entity.NonCaseString;
-import com.softdev.system.generator.entity.ParamInfo;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * 表格解析Util
- *
- * @author zhengkai.blog.csdn.net
- */
-public class TableParseUtil {
-
-
-
-}
diff --git a/generator-web/src/main/resources/statics/js/newui2.js b/generator-web/src/main/resources/statics/js/newui2.js
deleted file mode 100644
index 7eb6d42c..00000000
--- a/generator-web/src/main/resources/statics/js/newui2.js
+++ /dev/null
@@ -1,236 +0,0 @@
-//iframe自适应
-$(window).on('resize', function() {
- const $content = $('.content');
- $content.height($(this).height() - 154);
- $content.find('iframe').each(function() {
- $(this).height($content.height());
- });
-}).resize();
-
-const vm = new Vue({
- el: '#rrapp',
- data: {
- main: "main",
- },
- methods: {
- donate: function () {
- }
- },
- created: function () {
-
- },
- updated: function () {
- }
-});
-
-
-$.inputArea = undefined;
-$.outputArea = undefined;
-
-$(function(){
- //powered by zhengkai.blog.csdn.net
-
- //init input code area
- $.inputArea = CodeMirror.fromTextArea(document.getElementById("inputArea"), {
- mode: "text/x-sql", // SQL
- theme: "idea", // IDEA主题
- lineNumbers: true, //显示行号
- smartIndent: true, // 自动缩进
- autoCloseBrackets: true// 自动补全括号
- });
- $.inputArea.setSize('auto','auto');
-
- // init output code area
- $.outputArea = CodeMirror.fromTextArea(document.getElementById("outputArea"), {
- mode: "text/x-java", // JAV
- theme: "idea", // IDEA主题
- lineNumbers: true, //显示行号
- smartIndent: true, // 自动缩进
- autoCloseBrackets: true// 自动补全括号
- });
- $.outputArea.setSize('auto','auto');
-
-});
-
-
-const vm = new Vue({
- el: '#rrapp',
- data: {
- formData: {
- tableSql: "CREATE TABLE 'sys_user_info' (\n" +
- " 'user_id' int(11) NOT NULL AUTO_INCREMENT COMMENT '用户编号',\n" +
- " 'user_name' varchar(255) NOT NULL COMMENT '用户名',\n" +
- " 'status' tinyint(1) NOT NULL COMMENT '状态',\n" +
- " 'create_time' datetime NOT NULL COMMENT '创建时间',\n" +
- //下面可以留着方便开发调试时打开
- // " `updateTime` datetime NOT NULL COMMENT '更新时间',\n" +
- // " ABc_under_Line-Hypen-CamelCase varchar comment '乱七八糟的命名风格',\n" +
- " PRIMARY KEY ('user_id')\n" +
- ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息'",
- options: {
- dataType: "sql",
-
- authorName: "${(value.author)!!}",
- packageName: "${(value.packageName)!!}",
- returnUtilSuccess: "${(value.returnUtilSuccess)!!}",
- returnUtilFailure: "${(value.returnUtilFailure)!!}",
-
- isPackageType: true,
- isSwagger: false,
- isAutoImport: false,
- isWithPackage: false,
- isComment: true,
- isLombok: true,
-
- ignorePrefix:"sys_",
- tinyintTransType: "int",
- nameCaseType: "CamelCase",
- timeTransType: "Date"
- }
- },
- templates:[{}],
- historicalData:[],
- currentSelect:'plusentity',
- outputStr: "${(value.outputStr)!!}",
- outputJson: {}
- },
- methods: {
- //set the template for output 选择页面输出的模板类型
- setOutputModel: function (event) {
- const targetModel = event.target.innerText.trim();
- console.log(targetModel);
- vm.currentSelect = targetModel ;
- if(vm.outputStr.length>30){
- vm.outputStr=vm.outputJson[targetModel];
- $.outputArea.setValue(vm.outputStr.trim());
- //console.log(vm.outputStr);
- $.outputArea.setSize('auto', 'auto');
- }
- },
- //switch HistoricalData
- switchHistoricalData: function (event) {
- const tableName = event.target.innerText.trim();
- console.log(tableName);
- if (window.sessionStorage){
- const valueSession = sessionStorage.getItem(tableName);
- vm.outputJson = JSON.parse(valueSession);
- console.log(valueSession);
- alert("切换历史记录成功:"+tableName);
- }else{
- alert("浏览器不支持sessionStorage");
- }
- vm.outputStr=vm.outputJson[vm.currentSelect].trim();
- $.outputArea.setValue(vm.outputStr);
- //console.log(vm.outputStr);
- $.outputArea.setSize('auto', 'auto');
- },
- setHistoricalData : function (tableName){
- //add new table only
- if(vm.historicalData.indexOf(tableName)<0){
- vm.historicalData.unshift(tableName);
- }
- //remove last record , if more than N
- if(vm.historicalData.length>9){
- vm.historicalData.splice(9,1);
- }
- //get and set to session data
- const valueSession = sessionStorage.getItem(tableName);
- //remove if exists
- if(valueSession!==undefined && valueSession!=null){
- sessionStorage.removeItem(tableName);
- }
- //set data to session
- sessionStorage.setItem(tableName,JSON.stringify(vm.outputJson));
- //console.log(vm.historicalData);
- },
- //request with formData to generate the code 根据参数生成代码
- generate : function(){
- //get value from codemirror
- vm.formData.tableSql=$.inputArea.getValue();
- axios.post(basePath+"/code/generate",vm.formData).then(function(res){
- if(res.code===500){
- error("生成失败,请检查SQL语句!!!");
- return;
- }
- setAllCookie();
- //console.log(res.outputJson);
- //兼容后端返回数据格式
- if(res.data){
- vm.outputJson = res.data.outputJson;
- }else {
- vm.outputJson = res.outputJson;
- }
-
- // console.log(vm.outputJson["bootstrap-ui"]);
- vm.outputStr=vm.outputJson[vm.currentSelect].trim();
- //console.log(vm.outputJson["bootstrap-ui"]);
- //console.log(vm.outputStr);
- $.outputArea.setValue(vm.outputStr);
- $.outputArea.setSize('auto', 'auto');
- //add to historicalData
- vm.setHistoricalData(vm.outputJson.tableName);
- alert("生成成功");
- });
- },
- copy : function (){
- navigator.clipboard.writeText(vm.outputStr.trim()).then(r => {alert("已复制")});
- }
- },
- created: function () {
- //load all templates for selections 加载所有模板供选择
- axios.post(basePath+"/template/all",{
- id:1234
- }).then(function(res){
- //console.log(res.templates);
- // vm.templates = JSON.parse(res.templates);
- // console.log(res);
- //兼容后端返回数据格式
- if(res.data){
- vm.templates = res.data.templates;
- }else {
- vm.templates = res.templates;
- }
- });
- },
- updated: function () {
- }
-});
-
-/**
- * 将所有 需要 保留历史纪录的字段写入Cookie中
- */
-function setAllCookie() {
- var arr = list_key_need_load();
- for (var str of arr){
- setOneCookie(str);
- }
-}
-
-function setOneCookie(key) {
- setCookie(key, vm.formData.options[key]);
-}
-
-/**
- * 将所有 历史纪录 重加载回页面
- */
-function loadAllCookie() {
- //console.log(vm);
- var arr = list_key_need_load();
- for (var str of arr){
- loadOneCookie(str);
- }
-}
-
-function loadOneCookie(key) {
- if (getCookie(key)!==""){
- vm.formData.options[key] = getCookie(key);
- }
-}
-
-/**
- * 将 所有 需要 纪录的 字段写入数组
- * @returns {[string]}
- */
-function list_key_need_load() {
- return ["authorName","packageName","returnUtilSuccess","returnUtilFailure","ignorePrefix","tinyintTransType","timeTransType"];
-}
diff --git a/pom.xml b/pom.xml
index 840dff51..b95a209f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,19 +5,15 @@
com.softdev.system
SpringBootCodeGenerator
- 2023
- pom
+ 2025
+ jar
org.springframework.boot
spring-boot-starter-parent
- 3.5.5
+ 3.5.8
-
- generator-web
-
-
alimaven
@@ -41,6 +37,16 @@
jsqlparser
5.3
+
+ junit
+ junit
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-autoconfigure
+
org.springframework.boot
@@ -70,27 +76,21 @@
com.alibaba.fastjson2
fastjson2
- 2.0.58
+ 2.0.60
com.alibaba.fastjson2
fastjson2-extension
- 2.0.58
+ 2.0.60
com.alibaba.fastjson2
fastjson2-extension-spring6
- 2.0.58
+ 2.0.59
-
-
- jakarta.servlet
- jakarta.servlet-api
- 6.1.0
- provided
-
+
org.springframework.boot
@@ -117,7 +117,7 @@
org.projectlombok
lombok
- 1.18.40
+ 1.18.42
@@ -136,7 +136,7 @@
jakarta.xml.bind
jakarta.xml.bind-api
- 4.0.2
+ 4.0.4
diff --git a/generator-web/src/main/java/com/softdev/system/generator/Application.java b/src/main/java/com/softdev/system/generator/Application.java
similarity index 82%
rename from generator-web/src/main/java/com/softdev/system/generator/Application.java
rename to src/main/java/com/softdev/system/generator/Application.java
index 7779bed9..08ffe23b 100644
--- a/generator-web/src/main/java/com/softdev/system/generator/Application.java
+++ b/src/main/java/com/softdev/system/generator/Application.java
@@ -6,7 +6,7 @@
/**
* @author zhengkai.blog.csdn.net
*/
-@SpringBootApplication
+@SpringBootApplication(scanBasePackages = "com.softdev.system.generator")
public class Application {
public static void main(String[] args) {
diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java b/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java
similarity index 70%
rename from generator-web/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java
rename to src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java
index 837df06b..0687f9a8 100644
--- a/generator-web/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java
+++ b/src/main/java/com/softdev/system/generator/config/GlobalDefaultExceptionHandler.java
@@ -1,12 +1,11 @@
package com.softdev.system.generator.config;
-import com.softdev.system.generator.entity.ReturnT;
+import com.softdev.system.generator.entity.vo.ResultVo;
+import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
-import jakarta.servlet.http.HttpServletRequest;
-
/**
* @author zhengkai.blog.csdn.net
*/
@@ -15,9 +14,9 @@ public class GlobalDefaultExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
- public ReturnT defaultExceptionHandler(HttpServletRequest req, Exception e) {
+ public ResultVo defaultExceptionHandler(HttpServletRequest req, Exception e) {
e.printStackTrace();
- return ReturnT.error("代码生成失败:"+e.getMessage());
+ return ResultVo.error("代码生成失败:"+e.getMessage());
}
}
diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/HTMLFilter.java b/src/main/java/com/softdev/system/generator/config/HTMLFilter.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/config/HTMLFilter.java
rename to src/main/java/com/softdev/system/generator/config/HTMLFilter.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java b/src/main/java/com/softdev/system/generator/config/ServerConfig.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java
rename to src/main/java/com/softdev/system/generator/config/ServerConfig.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java b/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java
similarity index 90%
rename from generator-web/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java
rename to src/main/java/com/softdev/system/generator/config/WebMvcConfig.java
index 9f9420a6..dcc1354c 100644
--- a/generator-web/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java
+++ b/src/main/java/com/softdev/system/generator/config/WebMvcConfig.java
@@ -1,25 +1,16 @@
package com.softdev.system.generator.config;
-
-// import com.alibaba.fastjson.support.config.FastJsonConfig;
-// import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
-import jakarta.servlet.DispatcherType;
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
-import org.springframework.context.annotation.Bean;
+import com.alibaba.fastjson2.JSONReader;
+import com.alibaba.fastjson2.JSONWriter;
+import com.alibaba.fastjson2.support.config.FastJsonConfig;
+import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import com.alibaba.fastjson2.JSONReader;
-import com.alibaba.fastjson2.JSONWriter;
-import com.alibaba.fastjson2.support.config.FastJsonConfig;
-import com.alibaba.fastjson2.support.spring6.http.converter.FastJsonHttpMessageConverter;
-
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
diff --git a/src/main/java/com/softdev/system/generator/controller/CodeGenController.java b/src/main/java/com/softdev/system/generator/controller/CodeGenController.java
new file mode 100644
index 00000000..c11810b8
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/controller/CodeGenController.java
@@ -0,0 +1,29 @@
+package com.softdev.system.generator.controller;
+
+import com.softdev.system.generator.entity.dto.ParamInfo;
+import com.softdev.system.generator.entity.vo.ResultVo;
+import com.softdev.system.generator.service.CodeGenService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * 代码生成控制器
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Slf4j
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/code")
+public class CodeGenController {
+
+ private final CodeGenService codeGenService;
+
+ @PostMapping("/generate")
+ public ResultVo generateCode(@RequestBody ParamInfo paramInfo) throws Exception {
+ return codeGenService.generateCode(paramInfo);
+ }
+
+}
\ No newline at end of file
diff --git a/generator-web/src/main/resources/statics/libs/axios/axios.min.map b/src/main/java/com/softdev/system/generator/controller/GeneratorController.java
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/axios/axios.min.map
rename to src/main/java/com/softdev/system/generator/controller/GeneratorController.java
diff --git a/src/main/java/com/softdev/system/generator/controller/PageController.java b/src/main/java/com/softdev/system/generator/controller/PageController.java
new file mode 100644
index 00000000..efb2ae6b
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/controller/PageController.java
@@ -0,0 +1,30 @@
+package com.softdev.system.generator.controller;
+
+import com.softdev.system.generator.util.ValueUtil;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+/**
+ * 页面控制器
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@RequiredArgsConstructor
+@Controller
+public class PageController {
+
+ private final ValueUtil valueUtil;
+
+ @GetMapping("/")
+ public ModelAndView defaultPage() {
+ return new ModelAndView("newui2").addObject("value", valueUtil);
+ }
+
+ @GetMapping("/index")
+ public ModelAndView indexPage() {
+ return new ModelAndView("newui2").addObject("value", valueUtil);
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/controller/TemplateController.java b/src/main/java/com/softdev/system/generator/controller/TemplateController.java
new file mode 100644
index 00000000..5dfe84f4
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/controller/TemplateController.java
@@ -0,0 +1,28 @@
+package com.softdev.system.generator.controller;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.softdev.system.generator.entity.vo.ResultVo;
+import com.softdev.system.generator.service.TemplateService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 模板管理控制器
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/template")
+public class TemplateController {
+
+ private final TemplateService templateService;
+
+ @PostMapping("/all")
+ public ResultVo getAllTemplates() throws Exception {
+ return ResultVo.ok(templateService.getAllTemplates());
+ }
+
+}
\ No newline at end of file
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java b/src/main/java/com/softdev/system/generator/entity/ClassInfo.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/entity/ClassInfo.java
rename to src/main/java/com/softdev/system/generator/entity/ClassInfo.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/FieldInfo.java b/src/main/java/com/softdev/system/generator/entity/FieldInfo.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/entity/FieldInfo.java
rename to src/main/java/com/softdev/system/generator/entity/FieldInfo.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/NonCaseString.java b/src/main/java/com/softdev/system/generator/entity/NonCaseString.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/entity/NonCaseString.java
rename to src/main/java/com/softdev/system/generator/entity/NonCaseString.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java b/src/main/java/com/softdev/system/generator/entity/ParamInfo.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java
rename to src/main/java/com/softdev/system/generator/entity/ParamInfo.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/entity/TemplateConfig.java b/src/main/java/com/softdev/system/generator/entity/TemplateConfig.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/entity/TemplateConfig.java
rename to src/main/java/com/softdev/system/generator/entity/TemplateConfig.java
diff --git a/src/main/java/com/softdev/system/generator/entity/dto/ClassInfo.java b/src/main/java/com/softdev/system/generator/entity/dto/ClassInfo.java
new file mode 100644
index 00000000..97e5f410
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/entity/dto/ClassInfo.java
@@ -0,0 +1,21 @@
+package com.softdev.system.generator.entity.dto;
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 类信息
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Data
+public class ClassInfo {
+
+ private String tableName;
+ private String originTableName;
+ private String className;
+ private String classComment;
+ private List fieldList;
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/entity/dto/FieldInfo.java b/src/main/java/com/softdev/system/generator/entity/dto/FieldInfo.java
new file mode 100644
index 00000000..54ef3109
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/entity/dto/FieldInfo.java
@@ -0,0 +1,19 @@
+package com.softdev.system.generator.entity.dto;
+
+import lombok.Data;
+
+/**
+ * 字段信息
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Data
+public class FieldInfo {
+
+ private String columnName;
+ private String fieldName;
+ private String fieldClass;
+ private String swaggerClass;
+ private String fieldComment;
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/entity/dto/ParamInfo.java b/src/main/java/com/softdev/system/generator/entity/dto/ParamInfo.java
new file mode 100644
index 00000000..e6d3bd98
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/entity/dto/ParamInfo.java
@@ -0,0 +1,25 @@
+package com.softdev.system.generator.entity.dto;
+
+import lombok.Data;
+
+import java.util.Map;
+
+/**
+ * 请求参数信息
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Data
+public class ParamInfo {
+
+ private String tableSql;
+ private Map options;
+
+ @Data
+ public static class NameCaseType {
+ public static final String CAMEL_CASE = "CamelCase";
+ public static final String UNDER_SCORE_CASE = "UnderScoreCase";
+ public static final String UPPER_UNDER_SCORE_CASE = "UpperUnderScoreCase";
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/entity/enums/ParserTypeEnum.java b/src/main/java/com/softdev/system/generator/entity/enums/ParserTypeEnum.java
new file mode 100644
index 00000000..c09e598a
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/entity/enums/ParserTypeEnum.java
@@ -0,0 +1,38 @@
+package com.softdev.system.generator.entity.enums;
+
+import lombok.Getter;
+
+/**
+ * 解析类型枚举
+ */
+@Getter
+public enum ParserTypeEnum {
+
+ /**
+ * SQL解析类型
+ */
+ SQL("sql", "默认SQL解析"),
+ JSON("json", "JSON解析"),
+ INSERT_SQL("insert-sql", "INSERT SQL解析"),
+ SQL_REGEX("sql-regex", "正则表达式SQL解析"),
+ SELECT_SQL("select-sql", "SELECT SQL解析"),
+ CREATE_SQL("create-sql", "CREATE SQL解析");
+
+ private final String value;
+ private final String description;
+
+ ParserTypeEnum(String value, String description) {
+ this.value = value;
+ this.description = description;
+ }
+
+ public static ParserTypeEnum fromValue(String value) {
+ for (ParserTypeEnum type : ParserTypeEnum.values()) {
+ if (type.getValue().equals(value)) {
+ return type;
+ }
+ }
+ // 默认返回SQL类型
+ return SQL;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/entity/vo/ResultVo.java b/src/main/java/com/softdev/system/generator/entity/vo/ResultVo.java
new file mode 100644
index 00000000..e07c2380
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/entity/vo/ResultVo.java
@@ -0,0 +1,50 @@
+package com.softdev.system.generator.entity.vo;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 统一返回结果VO
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Data
+public class ResultVo extends HashMap {
+
+ public ResultVo() {
+ put("code", 200);
+ put("msg", "success");
+ }
+
+ public static ResultVo ok() {
+ return new ResultVo();
+ }
+
+ public static ResultVo ok(Object data) {
+ ResultVo resultVo = new ResultVo();
+ resultVo.put("data", data);
+ return resultVo;
+ }
+
+ public static ResultVo error(String msg) {
+ ResultVo resultVo = new ResultVo();
+ resultVo.put("code", 500);
+ resultVo.put("msg", msg);
+ return resultVo;
+ }
+
+ public static ResultVo error(int code, String msg) {
+ ResultVo resultVo = new ResultVo();
+ resultVo.put("code", code);
+ resultVo.put("msg", msg);
+ return resultVo;
+ }
+
+ @Override
+ public ResultVo put(String key, Object value) {
+ super.put(key, value);
+ return this;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/CodeGenService.java b/src/main/java/com/softdev/system/generator/service/CodeGenService.java
new file mode 100644
index 00000000..0afd73f7
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/CodeGenService.java
@@ -0,0 +1,33 @@
+package com.softdev.system.generator.service;
+
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+import com.softdev.system.generator.entity.vo.ResultVo;
+
+import java.util.Map;
+
+/**
+ * 代码生成服务接口
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public interface CodeGenService {
+
+ /**
+ * 生成代码
+ *
+ * @param paramInfo 参数信息
+ * @return 生成的代码映射
+ * @throws Exception 生成过程中的异常
+ */
+ ResultVo generateCode(ParamInfo paramInfo) throws Exception;
+
+ /**
+ * 根据参数获取结果
+ *
+ * @param params 参数映射
+ * @return 结果映射
+ * @throws Exception 处理过程中的异常
+ */
+ Map getResultByParams(Map params) throws Exception;
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/TemplateService.java b/src/main/java/com/softdev/system/generator/service/TemplateService.java
new file mode 100644
index 00000000..0a8fa9db
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/TemplateService.java
@@ -0,0 +1,21 @@
+package com.softdev.system.generator.service;
+
+import com.alibaba.fastjson2.JSONArray;
+
+import java.io.IOException;
+
+/**
+ * 模板服务接口
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public interface TemplateService {
+
+ /**
+ * 获取所有模板配置
+ *
+ * @return 模板配置字符串
+ * @throws IOException IO异常
+ */
+ JSONArray getAllTemplates() throws IOException;
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/impl/CodeGenServiceImpl.java b/src/main/java/com/softdev/system/generator/service/impl/CodeGenServiceImpl.java
new file mode 100644
index 00000000..0c9dc2b7
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/impl/CodeGenServiceImpl.java
@@ -0,0 +1,120 @@
+package com.softdev.system.generator.service.impl;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+import com.softdev.system.generator.entity.enums.ParserTypeEnum;
+import com.softdev.system.generator.entity.vo.ResultVo;
+import com.softdev.system.generator.service.CodeGenService;
+import com.softdev.system.generator.service.TemplateService;
+import com.softdev.system.generator.service.parser.JsonParserService;
+import com.softdev.system.generator.service.parser.SqlParserService;
+import com.softdev.system.generator.util.FreemarkerUtil;
+import com.softdev.system.generator.util.MapUtil;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 代码生成服务实现类
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class CodeGenServiceImpl implements CodeGenService {
+
+ private final TemplateService templateService;
+ private final SqlParserService sqlParserService;
+ private final JsonParserService jsonParserService;
+
+ @Override
+ public ResultVo generateCode(ParamInfo paramInfo) throws Exception {
+ if (paramInfo.getTableSql() == null || paramInfo.getTableSql().isEmpty()) {
+ return ResultVo.error("表结构信息为空");
+ }
+
+ try {
+ // 1. Parse Table Structure 表结构解析
+ ClassInfo classInfo = parseTableStructure(paramInfo);
+
+ // 2. Set the params 设置表格参数
+ paramInfo.getOptions().put("classInfo", classInfo);
+ paramInfo.getOptions().put("tableName", classInfo == null ? System.currentTimeMillis() + "" : classInfo.getTableName());
+
+ // 3. generate the code by freemarker templates with parameters .
+ // Freemarker根据参数和模板生成代码
+ Map result = getResultByParams(paramInfo.getOptions());
+ log.info("table:{} - time:{} ", MapUtil.getString(result, "tableName"), System.currentTimeMillis());
+ return ResultVo.ok(result);
+ } catch (Exception e) {
+ log.error("代码生成失败", e);
+ return ResultVo.error("代码生成失败: " + e.getMessage());
+ }
+ }
+
+ @Override
+ public Map getResultByParams(Map params) throws Exception {
+ Map result = new HashMap<>(32);
+ result.put("tableName", MapUtil.getString(params, "tableName"));
+
+ // 处理模板生成逻辑
+ // 解析模板配置并生成代码
+ JSONArray parentTemplates = templateService.getAllTemplates();
+ for (int i = 0; i < parentTemplates.size(); i++) {
+ JSONObject parentTemplateObj = parentTemplates.getJSONObject(i);
+ JSONArray childTemplates = parentTemplateObj.getJSONArray("templates");
+ if (childTemplates != null) {
+ for (int x = 0; x < childTemplates.size(); x++) {
+ JSONObject childTemplate = childTemplates.getJSONObject(x);
+ String templatePath = parentTemplateObj.getString("group") + "/" + childTemplate.getString("name") + ".ftl";
+ String generatedCode = FreemarkerUtil.processString(templatePath, params);
+ result.put(childTemplate.getString("name"), generatedCode);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * 根据不同的解析类型解析表结构
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ * @throws Exception 解析异常
+ */
+ private ClassInfo parseTableStructure(ParamInfo paramInfo) throws Exception {
+ String dataType = MapUtil.getString(paramInfo.getOptions(), "dataType");
+ ParserTypeEnum parserType = ParserTypeEnum.fromValue(dataType);
+
+ switch (parserType) {
+ case SQL:
+ // 默认模式:parse DDL table structure from sql
+ return sqlParserService.processTableIntoClassInfo(paramInfo);
+ case JSON:
+ // JSON模式:parse field from json string
+ return jsonParserService.processJsonToClassInfo(paramInfo);
+ case INSERT_SQL:
+ // INSERT SQL模式:parse field from insert sql
+ return sqlParserService.processInsertSqlToClassInfo(paramInfo);
+ case SQL_REGEX:
+ // 正则表达式模式(非完善版本):parse sql by regex
+ return sqlParserService.processTableToClassInfoByRegex(paramInfo);
+ case SELECT_SQL:
+ // SelectSqlBySQLPraser模式:parse select sql by JSqlParser
+ return sqlParserService.generateSelectSqlBySQLPraser(paramInfo);
+ case CREATE_SQL:
+ // CreateSqlBySQLPraser模式:parse create sql by JSqlParser
+ return sqlParserService.generateCreateSqlBySQLPraser(paramInfo);
+ default:
+ // 默认模式:parse DDL table structure from sql
+ return sqlParserService.processTableIntoClassInfo(paramInfo);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/impl/TemplateServiceImpl.java b/src/main/java/com/softdev/system/generator/service/impl/TemplateServiceImpl.java
new file mode 100644
index 00000000..d670879b
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/impl/TemplateServiceImpl.java
@@ -0,0 +1,36 @@
+package com.softdev.system.generator.service.impl;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.softdev.system.generator.service.TemplateService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StreamUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.stream.Collectors;
+
+/**
+ * 模板服务实现类
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Slf4j
+@Service
+public class TemplateServiceImpl implements TemplateService {
+
+ private String templateConfig = null;
+
+ @Override
+ public JSONArray getAllTemplates() throws IOException {
+ if (templateConfig == null) {
+ ClassPathResource resource = new ClassPathResource("template.json");
+ try (InputStream inputStream = resource.getInputStream()) {
+ templateConfig = StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);
+ }
+ }
+ return JSONArray.parseArray(templateConfig);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/impl/parser/JsonParserServiceImpl.java b/src/main/java/com/softdev/system/generator/service/impl/parser/JsonParserServiceImpl.java
new file mode 100644
index 00000000..8621434d
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/impl/parser/JsonParserServiceImpl.java
@@ -0,0 +1,90 @@
+package com.softdev.system.generator.service.impl.parser;
+
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.FieldInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+import com.softdev.system.generator.service.parser.JsonParserService;
+import com.softdev.system.generator.util.exception.CodeGenException;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * JSON解析服务实现类
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+@Service
+public class JsonParserServiceImpl implements JsonParserService {
+
+ @Override
+ public ClassInfo processJsonToClassInfo(ParamInfo paramInfo) {
+ ClassInfo codeJavaInfo = new ClassInfo();
+ codeJavaInfo.setTableName("JsonDto");
+ codeJavaInfo.setClassName("JsonDto");
+ codeJavaInfo.setClassComment("JsonDto");
+
+ //support children json if forget to add '{' in front of json
+ if (paramInfo.getTableSql().trim().startsWith("\"")) {
+ paramInfo.setTableSql("{" + paramInfo.getTableSql());
+ }
+ try {
+ if (paramInfo.getTableSql().trim().startsWith("{")) {
+ JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
+ //parse FieldList by JSONObject
+ codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonObject));
+ } else if (paramInfo.getTableSql().trim().startsWith("[")) {
+ JSONArray jsonArray = JSONArray.parseArray(paramInfo.getTableSql().trim());
+ //parse FieldList by JSONObject
+ codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonArray.getJSONObject(0)));
+ }
+ } catch (Exception e) {
+ // JSON解析失败,抛出自定义异常
+ throw new CodeGenException("JSON格式不正确: " + e.getMessage());
+ }
+
+ return codeJavaInfo;
+ }
+
+ public List processJsonObjectToFieldList(JSONObject jsonObject) {
+ // field List
+ List fieldList = new ArrayList();
+ for (String jsonField : jsonObject.keySet()) {
+ FieldInfo fieldInfo = new FieldInfo();
+ fieldInfo.setFieldName(jsonField);
+ fieldInfo.setColumnName(jsonField);
+ fieldInfo.setFieldClass(String.class.getSimpleName());
+ fieldInfo.setFieldComment("father:" + jsonField);
+ fieldList.add(fieldInfo);
+ if (jsonObject.get(jsonField) instanceof JSONArray) {
+ JSONArray jsonArray = jsonObject.getJSONArray(jsonField);
+ for (Object arrayObject : jsonArray) {
+ FieldInfo fieldInfo2 = new FieldInfo();
+ fieldInfo2.setFieldName(arrayObject.toString());
+ fieldInfo2.setColumnName(arrayObject.toString());
+ fieldInfo2.setFieldClass(String.class.getSimpleName());
+ fieldInfo2.setFieldComment("children:" + arrayObject.toString());
+ fieldList.add(fieldInfo2);
+ }
+ } else if (jsonObject.get(jsonField) instanceof JSONObject) {
+ JSONObject subJsonObject = jsonObject.getJSONObject(jsonField);
+ for (String arrayObject : subJsonObject.keySet()) {
+ FieldInfo fieldInfo2 = new FieldInfo();
+ fieldInfo2.setFieldName(arrayObject.toString());
+ fieldInfo2.setColumnName(arrayObject.toString());
+ fieldInfo2.setFieldClass(String.class.getSimpleName());
+ fieldInfo2.setFieldComment("children:" + arrayObject.toString());
+ fieldList.add(fieldInfo2);
+ }
+ }
+ }
+ if (fieldList.size() < 1) {
+ throw new CodeGenException("JSON解析失败");
+ }
+ return fieldList;
+ }
+}
\ No newline at end of file
diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java b/src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java
similarity index 73%
rename from generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java
rename to src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java
index de98dbd5..e62e1f3b 100644
--- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java
+++ b/src/main/java/com/softdev/system/generator/service/impl/parser/SqlParserServiceImpl.java
@@ -1,11 +1,14 @@
-package com.softdev.system.generator.service;
+package com.softdev.system.generator.service.impl.parser;
import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONArray;
-import com.alibaba.fastjson2.JSONObject;
-import com.softdev.system.generator.entity.*;
-import com.softdev.system.generator.util.*;
-import freemarker.template.TemplateException;
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.FieldInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+import com.softdev.system.generator.service.parser.SqlParserService;
+import com.softdev.system.generator.util.MapUtil;
+import com.softdev.system.generator.util.StringUtilsPlus;
+import com.softdev.system.generator.util.exception.SqlParseException;
+import com.softdev.system.generator.util.mysqlJavaTypeUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
@@ -21,69 +24,23 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
-import java.io.*;
-import java.util.*;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
-import static net.sf.jsqlparser.parser.feature.Feature.createTable;
-
/**
- * GeneratorService
+ * SQL解析服务实现类
*
* @author zhengkai.blog.csdn.net
*/
@Slf4j
@Service
-public class GeneratorServiceImpl implements GeneratorService {
-
- String templateCpnfig = null;
-
- /**
- * 从项目中的JSON文件读取String
- *
- * @author zhengkai.blog.csdn.net
- */
- @Override
- public String getTemplateConfig() throws IOException {
- templateCpnfig = null;
- InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("template.json");
- templateCpnfig = new BufferedReader(new InputStreamReader(inputStream))
- .lines().collect(Collectors.joining(System.lineSeparator()));
- inputStream.close();
- //log.info(JSON.toJSONString(templateCpnfig));
- return templateCpnfig;
- }
-
- /**
- * 根据配置的Template模板进行遍历解析,得到生成好的String
- *
- * @author zhengkai.blog.csdn.net
- */
- @Override
- public Map getResultByParams(Map params) throws IOException, TemplateException {
- Map result = new HashMap<>(32);
- result.put("tableName", MapUtil.getString(params,"tableName"));
- JSONArray parentTemplates = JSONArray.parseArray(getTemplateConfig());
- for (int i = 0; i
+ case ParamInfo.NameCaseType.CAMEL_CASE ->
// 2024-1-27 L&J 适配任意(maybe)原始风格转小写驼峰
StringUtilsPlus.toLowerCamel(aliasName);
- case ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(aliasName, false);
- case ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE ->
+ case ParamInfo.NameCaseType.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(aliasName, false);
+ case ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE ->
StringUtilsPlus.toUnderline(aliasName.toUpperCase(), true);
default -> aliasName;
};
@@ -147,13 +104,7 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except
log.info("classInfo:{}", JSON.toJSONString(classInfo));
return classInfo;
}
- /**
- * 根据SQL解析器解析表结构
- * @author zhengkai.blog.csdn.net
- * @param paramInfo
- * @return
- * @throws Exception
- */
+
@Override
public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
ClassInfo classInfo = new ClassInfo();
@@ -168,12 +119,12 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except
statement = CCJSqlParserUtil.parse(processedSql);
}catch (Exception e) {
e.printStackTrace();
- throw new SqlException("SQL语法错误:"+e.getMessage());
+ throw new SqlParseException("SQL语法错误:"+e.getMessage());
}
// 确保是CREATE TABLE语句
if (!(statement instanceof CreateTable createTable)) {
- throw new SqlException("检测到SQL语句不是DLL CREATE TABLE语句");
+ throw new SqlParseException("检测到SQL语句不是DLL CREATE TABLE语句");
}
// 提取表名
@@ -200,9 +151,9 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except
// 根据命名规则转换字段名
String fieldName = switch ((String) paramInfo.getOptions().get("nameCaseType")) {
- case ParamInfo.NAME_CASE_TYPE.CAMEL_CASE -> StringUtilsPlus.toLowerCamel(columnName);
- case ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(columnName, false);
- case ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE ->
+ case ParamInfo.NameCaseType.CAMEL_CASE -> StringUtilsPlus.toLowerCamel(columnName);
+ case ParamInfo.NameCaseType.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(columnName, false);
+ case ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE ->
StringUtilsPlus.toUnderline(columnName.toUpperCase(), true);
default -> columnName;
};
@@ -218,23 +169,17 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except
log.info("classInfo:{}", JSON.toJSONString(classInfo));
return classInfo;
}
- /**
- * 解析DDL SQL生成类信息(默认模式|核心模式)
- *
- * @param paramInfo
- * @return
- */
+
@Override
- public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
- throws IOException {
+ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception {
//process the param
- NonCaseString tableSql = NonCaseString.of(paramInfo.getTableSql());
+ String tableSql = paramInfo.getTableSql();
String nameCaseType = MapUtil.getString(paramInfo.getOptions(),"nameCaseType");
- Boolean isPackageType = MapUtil.getBoolean(paramInfo.getOptions(),"isPackageType");
+ String isPackageType = MapUtil.getString(paramInfo.getOptions(),"isPackageType");
//更新空值处理
if (StringUtils.isBlank(tableSql)) {
- throw new CodeGenerateException("Table structure can not be empty. 表结构不能为空。");
+ throw new Exception("Table structure can not be empty. 表结构不能为空。");
}
//deal with special character
tableSql = tableSql.trim()
@@ -250,9 +195,9 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
String tableName = null;
int tableKwIx = tableSql.indexOf("TABLE"); // 包含判断和位置一次搞定
if (tableKwIx > -1 && tableSql.contains("(")) {
- tableName = tableSql.substring(tableKwIx + 5, tableSql.indexOf("(")).get();
+ tableName = tableSql.substring(tableKwIx + 5, tableSql.indexOf("("));
} else {
- throw new CodeGenerateException("Table structure incorrect.表结构不正确。");
+ throw new Exception("Table structure incorrect.表结构不正确。");
}
//新增处理create table if not exists members情况
@@ -288,11 +233,11 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
String classComment = null;
//mysql是comment=,pgsql/oracle是comment on table,
//2020-05-25 优化表备注的获取逻辑
- if (tableSql.containsAny("comment=", "comment on table")) {
+ if (tableSql.contains("comment=") || tableSql.contains("comment on table")) {
int ix = tableSql.lastIndexOf("comment=");
String classCommentTmp = (ix > -1) ?
- tableSql.substring(ix + 8).trim().get() :
- tableSql.substring(tableSql.lastIndexOf("comment on table") + 17).trim().get();
+ tableSql.substring(ix + 8).trim() :
+ tableSql.substring(tableSql.lastIndexOf("comment on table") + 17).trim();
if (classCommentTmp.contains("`")) {
classCommentTmp = classCommentTmp.substring(classCommentTmp.indexOf("`") + 1);
classCommentTmp = classCommentTmp.substring(0, classCommentTmp.indexOf("`"));
@@ -311,7 +256,7 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
List fieldList = new ArrayList();
// 正常( ) 内的一定是字段相关的定义。
- String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")")).get();
+ String fieldListTmp = tableSql.substring(tableSql.indexOf("(") + 1, tableSql.lastIndexOf(")"));
// 匹配 comment,替换备注里的小逗号, 防止不小心被当成切割符号切割
String commentPattenStr1 = "comment `(.*?)\\`";
@@ -352,17 +297,27 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
int i = 0;
//i为了解决primary key关键字出现的地方,出现在前3行,一般和id有关
for (String columnLine0 : fieldLineList) {
- NonCaseString columnLine = NonCaseString.of(columnLine0);
i++;
- columnLine = columnLine.replaceAll("\n", "").replaceAll("\t", "").trim();
+ String columnLine = columnLine0.replaceAll("\n", "").replaceAll("\t", "").trim();
// `userid` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户ID',
// 2018-9-18 zhengk 修改为contains,提升匹配率和匹配不按照规矩出牌的语句
// 2018-11-8 zhengkai 修复tornadoorz反馈的KEY FK_permission_id (permission_id),KEY FK_role_id (role_id)情况
// 2019-2-22 zhengkai 要在条件中使用复杂的表达式
// 2019-4-29 zhengkai 优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 )
// 2020-10-20 zhengkai 优化对fulltext/index关键字的处理(感谢@WEGFan的反馈)
- // 2023-8-27 L&J 改用工具方法判断, 且修改变量名(非特殊标识), 方法抽取
- boolean notSpecialFlag = isNotSpecialColumnLine(columnLine, i);
+ boolean notSpecialFlag = (
+ !columnLine.contains("key ")
+ && !columnLine.contains("constraint")
+ && !columnLine.contains(" using ")
+ && !columnLine.contains("unique ")
+ && !columnLine.contains("fulltext ")
+ && !columnLine.contains("index ")
+ && !columnLine.contains("pctincrease")
+ && !columnLine.contains("buffer_pool")
+ && !columnLine.contains("tablespace")
+ && !(columnLine.contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
+ && !(columnLine.contains("primary ") && i > 3)
+ );
if (notSpecialFlag) {
//如果是oracle的number(x,x),可能出现最后分割残留的,x),这里做排除处理
@@ -374,7 +329,7 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
columnLine = columnLine.replaceAll("`", " ").replaceAll("\"", " ").replaceAll("'", "").replaceAll(" ", " ").trim();
//如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前
try {
- columnName = columnLine.substring(0, columnLine.indexOf(" ")).get();
+ columnName = columnLine.substring(0, columnLine.indexOf(" "));
} catch (StringIndexOutOfBoundsException e) {
System.out.println("err happened: " + columnLine);
throw e;
@@ -384,19 +339,19 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
// 2023-8-27 L&J 支持原始列名任意命名风格, 不依赖用户是否输入下划线
String fieldName = null;
- if (ParamInfo.NAME_CASE_TYPE.CAMEL_CASE.equals(nameCaseType)) {
+ if (ParamInfo.NameCaseType.CAMEL_CASE.equals(nameCaseType)) {
// 2024-1-27 L&J 适配任意(maybe)原始风格转小写驼峰
fieldName = StringUtilsPlus.toLowerCamel(columnName);
- } else if (ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE.equals(nameCaseType)) {
+ } else if (ParamInfo.NameCaseType.UNDER_SCORE_CASE.equals(nameCaseType)) {
fieldName = StringUtilsPlus.toUnderline(columnName, false);
- } else if (ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE.equals(nameCaseType)) {
+ } else if (ParamInfo.NameCaseType.UPPER_UNDER_SCORE_CASE.equals(nameCaseType)) {
fieldName = StringUtilsPlus.toUnderline(columnName.toUpperCase(), true);
} else {
fieldName = columnName;
}
columnLine = columnLine.substring(columnLine.indexOf("`") + 1).trim();
//2025-03-16 修复由于类型大写导致无法转换的问题
- String mysqlType = columnLine.split("\\s+")[1].toLowerCase(Locale.ROOT);
+ String mysqlType = columnLine.split("\\s+")[1].toLowerCase();
if(mysqlType.contains("(")){
mysqlType = mysqlType.substring(0, mysqlType.indexOf("("));
}
@@ -428,12 +383,12 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
while (columnCommentMatcher.find()) {
String columnCommentTmp = columnCommentMatcher.group();
//System.out.println(columnCommentTmp);
- fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp) + columnCommentTmp.length()).trim().get();
+ fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp) + columnCommentTmp.length()).trim();
fieldComment = fieldComment.substring(0, fieldComment.indexOf("`")).trim();
}
} else if (columnLine.contains(" comment")) {
//20200518 zhengkai 修复包含comment关键字的问题
- String commentTmp = columnLine.substring(columnLine.lastIndexOf("comment") + 7).trim().get();
+ String commentTmp = columnLine.substring(columnLine.lastIndexOf("comment") + 7).trim();
// '用户ID',
if (commentTmp.contains("`") || commentTmp.indexOf("`") != commentTmp.lastIndexOf("`")) {
commentTmp = commentTmp.substring(commentTmp.indexOf("`") + 1, commentTmp.lastIndexOf("`"));
@@ -462,7 +417,7 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
}
if (fieldList.size() < 1) {
- throw new CodeGenerateException("表结构分析失败,请检查语句或者提交issue给我");
+ throw new Exception("表结构分析失败,请检查语句或者提交issue给我");
}
ClassInfo codeJavaInfo = new ClassInfo();
@@ -475,63 +430,7 @@ public ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
return codeJavaInfo;
}
- private static boolean isNotSpecialColumnLine(NonCaseString columnLine, int lineSeq) {
- return (
- !columnLine.containsAny(
- "key ",
- "constraint",
- " using ",
- "unique ",
- "fulltext ",
- "index ",
- "pctincrease",
- "buffer_pool",
- "tablespace"
- )
- && !(columnLine.contains("primary ") && columnLine.indexOf("storage") + 3 > columnLine.indexOf("("))
- && !(columnLine.contains("primary ") && lineSeq > 3)
- );
- }
-
- /**
- * 解析JSON生成类信息
- *
- * @param paramInfo
- * @return
- */
@Override
- public ClassInfo processJsonToClassInfo(ParamInfo paramInfo) {
- ClassInfo codeJavaInfo = new ClassInfo();
- codeJavaInfo.setTableName("JsonDto");
- codeJavaInfo.setClassName("JsonDto");
- codeJavaInfo.setClassComment("JsonDto");
-
- //support children json if forget to add '{' in front of json
- if (paramInfo.getTableSql().trim().startsWith("\"")) {
- paramInfo.setTableSql("{" + paramInfo.getTableSql());
- }
- if (JSON.isValid(paramInfo.getTableSql())) {
- if (paramInfo.getTableSql().trim().startsWith("{")) {
- JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
- //parse FieldList by JSONObject
- codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonObject));
- } else if (paramInfo.getTableSql().trim().startsWith("[")) {
- JSONArray jsonArray = JSONArray.parseArray(paramInfo.getTableSql().trim());
- //parse FieldList by JSONObject
- codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonArray.getJSONObject(0)));
- }
- }
-
- return codeJavaInfo;
- }
-
- /**
- * parse SQL by regex
- *
- * @param paramInfo
- * @return
- * @author https://github.com/ydq
- */
public ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo) {
// field List
List fieldList = new ArrayList();
@@ -548,7 +447,7 @@ public ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo) {
Pattern COL_PATTERN = Pattern.compile(COL_PATTERN_STR, Pattern.CASE_INSENSITIVE);
- Matcher matcher = DDL_PATTERN.matcher(paramInfo.getTableSql().trim());
+ Matcher matcher = Pattern.compile(DDL_PATTEN_STR).matcher(paramInfo.getTableSql().trim());
if (matcher.find()) {
String tableName = matcher.group("tableName");
String tableComment = matcher.group("tableComment");
@@ -577,42 +476,7 @@ public ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo) {
return codeJavaInfo;
}
- public List processJsonObjectToFieldList(JSONObject jsonObject) {
- // field List
- List fieldList = new ArrayList();
- jsonObject.keySet().stream().forEach(jsonField -> {
- FieldInfo fieldInfo = new FieldInfo();
- fieldInfo.setFieldName(jsonField);
- fieldInfo.setColumnName(jsonField);
- fieldInfo.setFieldClass(String.class.getSimpleName());
- fieldInfo.setFieldComment("father:" + jsonField);
- fieldList.add(fieldInfo);
- if (jsonObject.get(jsonField) instanceof JSONArray) {
- jsonObject.getJSONArray(jsonField).stream().forEach(arrayObject -> {
- FieldInfo fieldInfo2 = new FieldInfo();
- fieldInfo2.setFieldName(arrayObject.toString());
- fieldInfo2.setColumnName(arrayObject.toString());
- fieldInfo2.setFieldClass(String.class.getSimpleName());
- fieldInfo2.setFieldComment("children:" + arrayObject.toString());
- fieldList.add(fieldInfo2);
- });
- } else if (jsonObject.get(jsonField) instanceof JSONObject) {
- jsonObject.getJSONObject(jsonField).keySet().stream().forEach(arrayObject -> {
- FieldInfo fieldInfo2 = new FieldInfo();
- fieldInfo2.setFieldName(arrayObject.toString());
- fieldInfo2.setColumnName(arrayObject.toString());
- fieldInfo2.setFieldClass(String.class.getSimpleName());
- fieldInfo2.setFieldComment("children:" + arrayObject.toString());
- fieldList.add(fieldInfo2);
- });
- }
- });
- if (fieldList.size() < 1) {
- throw new CodeGenerateException("JSON解析失败");
- }
- return fieldList;
- }
-
+ @Override
public ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo) {
// field List
List fieldList = new ArrayList();
@@ -645,12 +509,14 @@ public ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo) {
List valueList = new ArrayList<>();
//add values as comment
- Arrays.stream(valueStr.split(",")).forEach(column -> {
+ String[] values = valueStr.split(",");
+ for (String column : values) {
valueList.add(column);
- });
+ }
AtomicInteger n = new AtomicInteger(0);
//add column to fleldList
- Arrays.stream(columnsSQL.replaceAll(" ", "").split(",")).forEach(column -> {
+ String[] columns = columnsSQL.replaceAll(" ", "").split(",");
+ for (String column : columns) {
FieldInfo fieldInfo2 = new FieldInfo();
fieldInfo2.setFieldName(column);
fieldInfo2.setColumnName(column);
@@ -660,14 +526,13 @@ public ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo) {
}
fieldList.add(fieldInfo2);
n.getAndIncrement();
- });
+ }
}
if (fieldList.size() < 1) {
- throw new CodeGenerateException("INSERT SQL解析失败");
+ throw new RuntimeException("INSERT SQL解析失败");
}
codeJavaInfo.setFieldList(fieldList);
return codeJavaInfo;
}
-
-}
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/parser/JsonParserService.java b/src/main/java/com/softdev/system/generator/service/parser/JsonParserService.java
new file mode 100644
index 00000000..360fd73e
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/parser/JsonParserService.java
@@ -0,0 +1,20 @@
+package com.softdev.system.generator.service.parser;
+
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+
+/**
+ * JSON解析服务接口
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public interface JsonParserService {
+
+ /**
+ * 解析JSON生成类信息
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ */
+ ClassInfo processJsonToClassInfo(ParamInfo paramInfo);
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/service/parser/SqlParserService.java b/src/main/java/com/softdev/system/generator/service/parser/SqlParserService.java
new file mode 100644
index 00000000..8d8d7c9c
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/service/parser/SqlParserService.java
@@ -0,0 +1,55 @@
+package com.softdev.system.generator.service.parser;
+
+import com.softdev.system.generator.entity.dto.ClassInfo;
+import com.softdev.system.generator.entity.dto.ParamInfo;
+
+/**
+ * SQL解析服务接口
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public interface SqlParserService {
+
+ /**
+ * 解析Select-SQL生成类信息(JSQLPraser版本)
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ * @throws Exception 解析异常
+ */
+ ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
+
+ /**
+ * 解析Create-SQL生成类信息(JSQLPraser版本)
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ * @throws Exception 解析异常
+ */
+ ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
+
+ /**
+ * 解析DDL-SQL生成类信息
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ * @throws Exception 解析异常
+ */
+ ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception;
+
+ /**
+ * 解析DDL SQL生成类信息-正则表达式版本
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ */
+ ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo);
+
+ /**
+ * 解析INSERT-SQL生成类信息-正则表达式版本
+ *
+ * @param paramInfo 参数信息
+ * @return 类信息
+ */
+ ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo);
+}
\ No newline at end of file
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/CodeGenerateException.java b/src/main/java/com/softdev/system/generator/util/CodeGenerateException.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/CodeGenerateException.java
rename to src/main/java/com/softdev/system/generator/util/CodeGenerateException.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java b/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java
rename to src/main/java/com/softdev/system/generator/util/FreemarkerUtil.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/MapUtil.java b/src/main/java/com/softdev/system/generator/util/MapUtil.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/MapUtil.java
rename to src/main/java/com/softdev/system/generator/util/MapUtil.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java b/src/main/java/com/softdev/system/generator/util/SqlException.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java
rename to src/main/java/com/softdev/system/generator/util/SqlException.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/StringUtilsPlus.java b/src/main/java/com/softdev/system/generator/util/StringUtilsPlus.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/StringUtilsPlus.java
rename to src/main/java/com/softdev/system/generator/util/StringUtilsPlus.java
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/ValueUtil.java b/src/main/java/com/softdev/system/generator/util/ValueUtil.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/ValueUtil.java
rename to src/main/java/com/softdev/system/generator/util/ValueUtil.java
diff --git a/src/main/java/com/softdev/system/generator/util/exception/CodeGenException.java b/src/main/java/com/softdev/system/generator/util/exception/CodeGenException.java
new file mode 100644
index 00000000..8bd9e657
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/util/exception/CodeGenException.java
@@ -0,0 +1,28 @@
+package com.softdev.system.generator.util.exception;
+
+/**
+ * 代码生成异常
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public class CodeGenException extends RuntimeException {
+
+ public CodeGenException() {
+ }
+
+ public CodeGenException(String message) {
+ super(message);
+ }
+
+ public CodeGenException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public CodeGenException(Throwable cause) {
+ super(cause);
+ }
+
+ public CodeGenException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/softdev/system/generator/util/exception/SqlParseException.java b/src/main/java/com/softdev/system/generator/util/exception/SqlParseException.java
new file mode 100644
index 00000000..3be73c83
--- /dev/null
+++ b/src/main/java/com/softdev/system/generator/util/exception/SqlParseException.java
@@ -0,0 +1,28 @@
+package com.softdev.system.generator.util.exception;
+
+/**
+ * SQL解析异常
+ *
+ * @author zhengkai.blog.csdn.net
+ */
+public class SqlParseException extends CodeGenException {
+
+ public SqlParseException() {
+ }
+
+ public SqlParseException(String message) {
+ super(message);
+ }
+
+ public SqlParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public SqlParseException(Throwable cause) {
+ super(cause);
+ }
+
+ public SqlParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
+ super(message, cause, enableSuppression, writableStackTrace);
+ }
+}
\ No newline at end of file
diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/mysqlJavaTypeUtil.java b/src/main/java/com/softdev/system/generator/util/mysqlJavaTypeUtil.java
similarity index 100%
rename from generator-web/src/main/java/com/softdev/system/generator/util/mysqlJavaTypeUtil.java
rename to src/main/java/com/softdev/system/generator/util/mysqlJavaTypeUtil.java
diff --git a/generator-web/src/main/resources/application-bejson.yml b/src/main/resources/application-bejson.yml
similarity index 100%
rename from generator-web/src/main/resources/application-bejson.yml
rename to src/main/resources/application-bejson.yml
diff --git a/generator-web/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
similarity index 100%
rename from generator-web/src/main/resources/application-dev.yml
rename to src/main/resources/application-dev.yml
diff --git a/generator-web/src/main/resources/application-json.yml b/src/main/resources/application-json.yml
similarity index 100%
rename from generator-web/src/main/resources/application-json.yml
rename to src/main/resources/application-json.yml
diff --git a/generator-web/src/main/resources/application.yml b/src/main/resources/application.yml
similarity index 100%
rename from generator-web/src/main/resources/application.yml
rename to src/main/resources/application.yml
diff --git a/generator-web/src/main/resources/statics/fonts/FontAwesome.otf b/src/main/resources/statics/fonts/FontAwesome.otf
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/FontAwesome.otf
rename to src/main/resources/statics/fonts/FontAwesome.otf
diff --git a/generator-web/src/main/resources/statics/fonts/fontawesome-webfont.eot b/src/main/resources/statics/fonts/fontawesome-webfont.eot
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/fontawesome-webfont.eot
rename to src/main/resources/statics/fonts/fontawesome-webfont.eot
diff --git a/generator-web/src/main/resources/statics/fonts/fontawesome-webfont.svg b/src/main/resources/statics/fonts/fontawesome-webfont.svg
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/fontawesome-webfont.svg
rename to src/main/resources/statics/fonts/fontawesome-webfont.svg
diff --git a/generator-web/src/main/resources/statics/fonts/fontawesome-webfont.ttf b/src/main/resources/statics/fonts/fontawesome-webfont.ttf
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/fontawesome-webfont.ttf
rename to src/main/resources/statics/fonts/fontawesome-webfont.ttf
diff --git a/generator-web/src/main/resources/statics/fonts/fontawesome-webfont.woff b/src/main/resources/statics/fonts/fontawesome-webfont.woff
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/fontawesome-webfont.woff
rename to src/main/resources/statics/fonts/fontawesome-webfont.woff
diff --git a/generator-web/src/main/resources/statics/fonts/fontawesome-webfont.woff2 b/src/main/resources/statics/fonts/fontawesome-webfont.woff2
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/fontawesome-webfont.woff2
rename to src/main/resources/statics/fonts/fontawesome-webfont.woff2
diff --git a/generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.eot b/src/main/resources/statics/fonts/glyphicons-halflings-regular.eot
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.eot
rename to src/main/resources/statics/fonts/glyphicons-halflings-regular.eot
diff --git a/generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.svg b/src/main/resources/statics/fonts/glyphicons-halflings-regular.svg
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.svg
rename to src/main/resources/statics/fonts/glyphicons-halflings-regular.svg
diff --git a/generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.ttf b/src/main/resources/statics/fonts/glyphicons-halflings-regular.ttf
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.ttf
rename to src/main/resources/statics/fonts/glyphicons-halflings-regular.ttf
diff --git a/generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff b/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff
rename to src/main/resources/statics/fonts/glyphicons-halflings-regular.woff
diff --git a/generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff2 b/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff2
similarity index 100%
rename from generator-web/src/main/resources/statics/fonts/glyphicons-halflings-regular.woff2
rename to src/main/resources/statics/fonts/glyphicons-halflings-regular.woff2
diff --git a/generator-web/src/main/resources/statics/js/common.js b/src/main/resources/statics/js/common.js
similarity index 100%
rename from generator-web/src/main/resources/statics/js/common.js
rename to src/main/resources/statics/js/common.js
diff --git a/generator-web/src/main/resources/statics/js/index.js b/src/main/resources/statics/js/index.js
similarity index 100%
rename from generator-web/src/main/resources/statics/js/index.js
rename to src/main/resources/statics/js/index.js
diff --git a/generator-web/src/main/resources/statics/js/main.js b/src/main/resources/statics/js/main.js
similarity index 93%
rename from generator-web/src/main/resources/statics/js/main.js
rename to src/main/resources/statics/js/main.js
index e714a1ac..3ed97bed 100644
--- a/generator-web/src/main/resources/statics/js/main.js
+++ b/src/main/resources/statics/js/main.js
@@ -130,12 +130,13 @@ const vm = new Vue({
}
setAllCookie();
//console.log(res.outputJson);
+ vm.outputJson = res.data.data;
//兼容后端返回数据格式
- if(res.data){
- vm.outputJson = res.data.outputJson;
- }else {
- vm.outputJson = res.outputJson;
- }
+// if(res.data){
+// vm.outputJson = res.data.outputJson;
+// }else {
+// vm.outputJson = res.outputJson;
+// }
// console.log(vm.outputJson["bootstrap-ui"]);
vm.outputStr=vm.outputJson[vm.currentSelect].trim();
@@ -159,13 +160,15 @@ const vm = new Vue({
}).then(function(res){
//console.log(res.templates);
// vm.templates = JSON.parse(res.templates);
- // console.log(res);
+ console.log('origin res',res);
+ vm.templates = res.data.data
+ console.log('templates',vm.templates);
//兼容后端返回数据格式
- if(res.data){
- vm.templates = res.data.templates;
- }else {
- vm.templates = res.templates;
- }
+// if(res.data){
+// vm.templates = res.data.templates;
+// }else {
+// vm.templates = res.templates;
+// }
});
},
updated: function () {
diff --git a/generator-web/src/main/resources/statics/js/navtab.js b/src/main/resources/statics/js/navtab.js
similarity index 100%
rename from generator-web/src/main/resources/statics/js/navtab.js
rename to src/main/resources/statics/js/navtab.js
diff --git a/generator-web/src/main/resources/statics/libs/axios/axios.min.js b/src/main/resources/statics/libs/axios/axios.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/axios/axios.min.js
rename to src/main/resources/statics/libs/axios/axios.min.js
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js.map b/src/main/resources/statics/libs/axios/axios.min.map
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js.map
rename to src/main/resources/statics/libs/axios/axios.min.map
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap-icons/bootstrap-icons.min.css b/src/main/resources/statics/libs/bootstrap-icons/bootstrap-icons.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap-icons/bootstrap-icons.min.css
rename to src/main/resources/statics/libs/bootstrap-icons/bootstrap-icons.min.css
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff b/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff
rename to src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff2 b/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff2
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff2
rename to src/main/resources/statics/libs/bootstrap-icons/fonts/bootstrap-icons.woff2
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js b/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js
rename to src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.css.map b/src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js.map
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.css.map
rename to src/main/resources/statics/libs/bootstrap/bootstrap.bundle.min.js.map
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.css b/src/main/resources/statics/libs/bootstrap/bootstrap.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.css
rename to src/main/resources/statics/libs/bootstrap/bootstrap.min.css
diff --git a/generator-web/src/main/resources/statics/libs/toastr.js/toastr.js.map b/src/main/resources/statics/libs/bootstrap/bootstrap.min.css.map
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/toastr.js/toastr.js.map
rename to src/main/resources/statics/libs/bootstrap/bootstrap.min.css.map
diff --git a/generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.js b/src/main/resources/statics/libs/bootstrap/bootstrap.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/bootstrap/bootstrap.min.js
rename to src/main/resources/statics/libs/bootstrap/bootstrap.min.js
diff --git a/generator-web/src/main/resources/statics/libs/codemirror/codemirror.min.css b/src/main/resources/statics/libs/codemirror/codemirror.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/codemirror/codemirror.min.css
rename to src/main/resources/statics/libs/codemirror/codemirror.min.css
diff --git a/generator-web/src/main/resources/statics/libs/codemirror/codemirror.min.js b/src/main/resources/statics/libs/codemirror/codemirror.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/codemirror/codemirror.min.js
rename to src/main/resources/statics/libs/codemirror/codemirror.min.js
diff --git a/generator-web/src/main/resources/statics/libs/codemirror/mode/clike/clike.min.js b/src/main/resources/statics/libs/codemirror/mode/clike/clike.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/codemirror/mode/clike/clike.min.js
rename to src/main/resources/statics/libs/codemirror/mode/clike/clike.min.js
diff --git a/generator-web/src/main/resources/statics/libs/codemirror/mode/sql/sql.min.js b/src/main/resources/statics/libs/codemirror/mode/sql/sql.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/codemirror/mode/sql/sql.min.js
rename to src/main/resources/statics/libs/codemirror/mode/sql/sql.min.js
diff --git a/generator-web/src/main/resources/statics/libs/codemirror/theme/idea.min.css b/src/main/resources/statics/libs/codemirror/theme/idea.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/codemirror/theme/idea.min.css
rename to src/main/resources/statics/libs/codemirror/theme/idea.min.css
diff --git a/generator-web/src/main/resources/statics/libs/element-ui/fonts/element-icons.woff b/src/main/resources/statics/libs/element-ui/fonts/element-icons.woff
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/element-ui/fonts/element-icons.woff
rename to src/main/resources/statics/libs/element-ui/fonts/element-icons.woff
diff --git a/generator-web/src/main/resources/statics/libs/element-ui/index.min.css b/src/main/resources/statics/libs/element-ui/index.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/element-ui/index.min.css
rename to src/main/resources/statics/libs/element-ui/index.min.css
diff --git a/generator-web/src/main/resources/statics/libs/element-ui/index.min.js b/src/main/resources/statics/libs/element-ui/index.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/element-ui/index.min.js
rename to src/main/resources/statics/libs/element-ui/index.min.js
diff --git a/generator-web/src/main/resources/statics/libs/jquery/jquery.min.js b/src/main/resources/statics/libs/jquery/jquery.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/jquery/jquery.min.js
rename to src/main/resources/statics/libs/jquery/jquery.min.js
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/rr-entity.ftl b/src/main/resources/statics/libs/toastr.js/toastr.js.map
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/rr-entity.ftl
rename to src/main/resources/statics/libs/toastr.js/toastr.js.map
diff --git a/generator-web/src/main/resources/statics/libs/toastr.js/toastr.min.css b/src/main/resources/statics/libs/toastr.js/toastr.min.css
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/toastr.js/toastr.min.css
rename to src/main/resources/statics/libs/toastr.js/toastr.min.css
diff --git a/generator-web/src/main/resources/statics/libs/toastr.js/toastr.min.js b/src/main/resources/statics/libs/toastr.js/toastr.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/toastr.js/toastr.min.js
rename to src/main/resources/statics/libs/toastr.js/toastr.min.js
diff --git a/generator-web/src/main/resources/statics/libs/vue/vue.min.js b/src/main/resources/statics/libs/vue/vue.min.js
similarity index 100%
rename from generator-web/src/main/resources/statics/libs/vue/vue.min.js
rename to src/main/resources/statics/libs/vue/vue.min.js
diff --git a/generator-web/src/main/resources/template.json b/src/main/resources/template.json
similarity index 100%
rename from generator-web/src/main/resources/template.json
rename to src/main/resources/template.json
diff --git a/generator-web/src/main/resources/templates/404.html b/src/main/resources/templates/404.html
similarity index 100%
rename from generator-web/src/main/resources/templates/404.html
rename to src/main/resources/templates/404.html
diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl b/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl
rename to src/main/resources/templates/code-generator/beetlsql/beetlcontroller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl b/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl
rename to src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/beetlsql/beetlmd.ftl b/src/main/resources/templates/code-generator/beetlsql/beetlmd.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/beetlsql/beetlmd.ftl
rename to src/main/resources/templates/code-generator/beetlsql/beetlmd.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/bi/qliksense.ftl b/src/main/resources/templates/code-generator/bi/qliksense.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/bi/qliksense.ftl
rename to src/main/resources/templates/code-generator/bi/qliksense.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/cloud/bigquery.ftl b/src/main/resources/templates/code-generator/cloud/bigquery.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/cloud/bigquery.ftl
rename to src/main/resources/templates/code-generator/cloud/bigquery.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/cloud/dataflowjjs.ftl b/src/main/resources/templates/code-generator/cloud/dataflowjjs.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/cloud/dataflowjjs.ftl
rename to src/main/resources/templates/code-generator/cloud/dataflowjjs.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl b/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/common-mapper/tkentity.ftl
rename to src/main/resources/templates/code-generator/common-mapper/tkentity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl b/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl
rename to src/main/resources/templates/code-generator/common-mapper/tkmapper.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl b/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl
rename to src/main/resources/templates/code-generator/jdbc-template/jtdao.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl b/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl
rename to src/main/resources/templates/code-generator/jdbc-template/jtdaoimpl.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-entity.ftl b/src/main/resources/templates/code-generator/jpa-starp/starp-entity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-entity.ftl
rename to src/main/resources/templates/code-generator/jpa-starp/starp-entity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-jpa-controller.ftl b/src/main/resources/templates/code-generator/jpa-starp/starp-jpa-controller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-jpa-controller.ftl
rename to src/main/resources/templates/code-generator/jpa-starp/starp-jpa-controller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-repository.ftl b/src/main/resources/templates/code-generator/jpa-starp/starp-repository.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa-starp/starp-repository.ftl
rename to src/main/resources/templates/code-generator/jpa-starp/starp-repository.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl b/src/main/resources/templates/code-generator/jpa/entity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl
rename to src/main/resources/templates/code-generator/jpa/entity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl b/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa/jpacontroller.ftl
rename to src/main/resources/templates/code-generator/jpa/jpacontroller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl b/src/main/resources/templates/code-generator/jpa/repository.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/jpa/repository.ftl
rename to src/main/resources/templates/code-generator/jpa/repository.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl b/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl
rename to src/main/resources/templates/code-generator/mybatis-plus/pluscontroller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl b/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl
rename to src/main/resources/templates/code-generator/mybatis-plus/plusentity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl b/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl
rename to src/main/resources/templates/code-generator/mybatis-plus/plusmapper.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusservice.ftl b/src/main/resources/templates/code-generator/mybatis-plus/plusservice.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis-plus/plusservice.ftl
rename to src/main/resources/templates/code-generator/mybatis-plus/plusservice.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl b/src/main/resources/templates/code-generator/mybatis/controller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/controller.ftl
rename to src/main/resources/templates/code-generator/mybatis/controller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl b/src/main/resources/templates/code-generator/mybatis/mapper.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/mapper.ftl
rename to src/main/resources/templates/code-generator/mybatis/mapper.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl b/src/main/resources/templates/code-generator/mybatis/mapper2.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/mapper2.ftl
rename to src/main/resources/templates/code-generator/mybatis/mapper2.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl b/src/main/resources/templates/code-generator/mybatis/model.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/model.ftl
rename to src/main/resources/templates/code-generator/mybatis/model.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/mybatis.ftl b/src/main/resources/templates/code-generator/mybatis/mybatis.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/mybatis.ftl
rename to src/main/resources/templates/code-generator/mybatis/mybatis.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl b/src/main/resources/templates/code-generator/mybatis/service.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/service.ftl
rename to src/main/resources/templates/code-generator/mybatis/service.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl b/src/main/resources/templates/code-generator/mybatis/service_impl.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/mybatis/service_impl.ftl
rename to src/main/resources/templates/code-generator/mybatis/service_impl.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/menu-sql.ftl b/src/main/resources/templates/code-generator/renren-fast/menu-sql.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/menu-sql.ftl
rename to src/main/resources/templates/code-generator/renren-fast/menu-sql.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/rr-controller.ftl b/src/main/resources/templates/code-generator/renren-fast/rr-controller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/rr-controller.ftl
rename to src/main/resources/templates/code-generator/renren-fast/rr-controller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/rr-dao.ftl b/src/main/resources/templates/code-generator/renren-fast/rr-dao.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/rr-dao.ftl
rename to src/main/resources/templates/code-generator/renren-fast/rr-dao.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/rr-daoxml.ftl b/src/main/resources/templates/code-generator/renren-fast/rr-daoxml.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/rr-daoxml.ftl
rename to src/main/resources/templates/code-generator/renren-fast/rr-daoxml.ftl
diff --git a/src/main/resources/templates/code-generator/renren-fast/rr-entity.ftl b/src/main/resources/templates/code-generator/renren-fast/rr-entity.ftl
new file mode 100644
index 00000000..e69de29b
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/rr-service.ftl b/src/main/resources/templates/code-generator/renren-fast/rr-service.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/rr-service.ftl
rename to src/main/resources/templates/code-generator/renren-fast/rr-service.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/vue-edit.ftl b/src/main/resources/templates/code-generator/renren-fast/vue-edit.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/vue-edit.ftl
rename to src/main/resources/templates/code-generator/renren-fast/vue-edit.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/renren-fast/vue-list.ftl b/src/main/resources/templates/code-generator/renren-fast/vue-list.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/renren-fast/vue-list.ftl
rename to src/main/resources/templates/code-generator/renren-fast/vue-list.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl b/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl
rename to src/main/resources/templates/code-generator/tk-mybatis/tk-controller.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl b/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl
rename to src/main/resources/templates/code-generator/tk-mybatis/tk-entity.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl b/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl
rename to src/main/resources/templates/code-generator/tk-mybatis/tk-mapper.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl b/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl
rename to src/main/resources/templates/code-generator/ui/bootstrap-ui.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl b/src/main/resources/templates/code-generator/ui/element-ui.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/ui/element-ui.ftl
rename to src/main/resources/templates/code-generator/ui/element-ui.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl b/src/main/resources/templates/code-generator/ui/layui-edit.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/ui/layui-edit.ftl
rename to src/main/resources/templates/code-generator/ui/layui-edit.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl b/src/main/resources/templates/code-generator/ui/layui-list.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/ui/layui-list.ftl
rename to src/main/resources/templates/code-generator/ui/layui-list.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/ui/swagger-ui.ftl b/src/main/resources/templates/code-generator/ui/swagger-ui.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/ui/swagger-ui.ftl
rename to src/main/resources/templates/code-generator/ui/swagger-ui.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl b/src/main/resources/templates/code-generator/util/beanutil.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/util/beanutil.ftl
rename to src/main/resources/templates/code-generator/util/beanutil.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/util/json.ftl b/src/main/resources/templates/code-generator/util/json.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/util/json.ftl
rename to src/main/resources/templates/code-generator/util/json.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/util/sql.ftl b/src/main/resources/templates/code-generator/util/sql.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/util/sql.ftl
rename to src/main/resources/templates/code-generator/util/sql.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/util/swagger-yml.ftl b/src/main/resources/templates/code-generator/util/swagger-yml.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/util/swagger-yml.ftl
rename to src/main/resources/templates/code-generator/util/swagger-yml.ftl
diff --git a/generator-web/src/main/resources/templates/code-generator/util/xml.ftl b/src/main/resources/templates/code-generator/util/xml.ftl
similarity index 100%
rename from generator-web/src/main/resources/templates/code-generator/util/xml.ftl
rename to src/main/resources/templates/code-generator/util/xml.ftl
diff --git a/generator-web/src/main/resources/templates/newui-header.html b/src/main/resources/templates/newui-header.html
similarity index 100%
rename from generator-web/src/main/resources/templates/newui-header.html
rename to src/main/resources/templates/newui-header.html
diff --git a/generator-web/src/main/resources/templates/newui-import-CDN.html b/src/main/resources/templates/newui-import-CDN.html
similarity index 100%
rename from generator-web/src/main/resources/templates/newui-import-CDN.html
rename to src/main/resources/templates/newui-import-CDN.html
diff --git a/generator-web/src/main/resources/templates/newui-import-local.html b/src/main/resources/templates/newui-import-local.html
similarity index 100%
rename from generator-web/src/main/resources/templates/newui-import-local.html
rename to src/main/resources/templates/newui-import-local.html
diff --git a/generator-web/src/main/resources/templates/newui2.html b/src/main/resources/templates/newui2.html
similarity index 100%
rename from generator-web/src/main/resources/templates/newui2.html
rename to src/main/resources/templates/newui2.html
diff --git a/generator-web/src/test/java/com/softdev/system/generator/util/StringUtilsPlusTest.java b/src/test/java/com/softdev/system/generator/util/StringUtilsPlusTest.java
similarity index 100%
rename from generator-web/src/test/java/com/softdev/system/generator/util/StringUtilsPlusTest.java
rename to src/test/java/com/softdev/system/generator/util/StringUtilsPlusTest.java