Skip to content

Commit b687f36

Browse files
committed
| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL
1 parent f11a656 commit b687f36

File tree

6 files changed

+53
-41
lines changed

6 files changed

+53
-41
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@
1010
>powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net)
1111
1212
# Description
13-
>The `Spring Boot Code Generator` , Based on SpringBoot3 and Freemarker<br>
14-
> #基于`SpringBoot3``Freemarker`的代码生成平台
15-
>
16-
>Free your hands from tedious and repetitive CRUD work.<br>
17-
> #解放你的双手,摆脱繁琐重复的CRUD工作。
18-
>
19-
>Support mysql+oracle+pgsql , the most popular databases standard SQL<br>
20-
> #支持`MySQL`、Oracle、PgSQL三大主流数据库
21-
>
22-
>Generate various templates through table creation DDL statements, Insert SQL statements, Select SQL statements(*New), and simple JSON.<br>
23-
> 通过建表DDL语句、插入SQL语句、选择SQL语句(*新)以及简单JSON生成各种模板`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper`.
24-
>
25-
>Thank you all for your use and feedback. The daily PV visits of 1.5k in BeJSON and 2K Stars on GitHub are the greatest encouragement and motivation. <br>
26-
> 感谢大家的使用与反馈,BeJSON上每天1.5K的PV访问量👀和 Github上2K的✨Stars是最大的鼓励与动力。
27-
>
28-
>May everyone maintain a work-life balance, stay healthy and safe. Wishing you all success in your work and continuous advancements!. <br>
29-
> 愿大家可以维持生活和工作平衡,保持健康和安全,祝大家工作顺利,步步高升!
30-
>
31-
>Welcome to submit your issue and useful templates , or put your good idea into PR <br>
32-
> 欢迎提交你的问题和常用有用模板,或者提交你的好主意到PR。
33-
34-
> 特别感谢BeJSON前站长`三叔`的慧眼和支持,让该项目得以脱颖而出,谢谢!
13+
> 🚀 `Spring Boot Code Generator` — a powerful code generation platform built on SpringBoot3 & Freemarker
14+
> ✨ 基于 `SpringBoot3``Freemarker` 的高效代码生成平台
15+
16+
> 👐 Say goodbye to repetitive CRUD work — free your hands and boost productivity
17+
> 💡 告别繁琐重复的 CRUD 操作,释放你的双手,让开发更高效!
18+
19+
> 🛠️ Supports MySQL, Oracle, and PostgreSQL — the most popular SQL dialects
20+
> 📦 支持主流数据库:`MySQL``Oracle``PgSQL`,标准 SQL 一网打尽
21+
22+
> ⚙️ Generate templates from DDL, INSERT SQL, SELECT SQL, or simple JSON — covering JPA, JdbcTemplate, Mybatis, MybatisPlus, BeetlSQL, CommonMapper
23+
> 🧩 通过建表 DDL、插入 SQL、选择 SQL 或简单 JSON,一键生成 `JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper` 等模板代码
24+
25+
> 🙏 Thanks for your continued support! BeJSON once peaked at 1.5K daily PV 👀, and now maintains a steady flow of around 600 visits — plus 2K+ GitHub Stars ✨. Your feedback remains our greatest motivation to keep improving!
26+
> ❤️ 感谢大家一直以来的支持!BeJSON 曾创下日均访问量 1.5K 👀 的高峰,目前稳定在约 600 左右,GitHub Star 数也已突破 2K ✨。你们的反馈始终是我们不断前进的最大动力!
27+
28+
> 🌈 Wishing everyone balance, health, and success — may your code be bug-free and your coffee strong ☕
29+
> 💬 祝大家工作顺利,生活平衡,身体健康,步步高升,代码无 bug,咖啡够劲!
30+
31+
> 📬 Feel free to submit issues, share useful templates, or contribute your brilliant ideas via PR
32+
> 🤝 欢迎提交问题、分享常用模板,或将你的灵感通过 PR 实现!
33+
34+
> 🙌 Special thanks to BeJSON 前站长 `三叔` 的慧眼与支持,让项目得以脱颖而出,感恩!
35+
3536

3637
# URL
3738

@@ -67,14 +68,14 @@
6768
- Master:主力分支,基于SpringBoot3+,需要JDK17+
6869
- JDK11:兼容分支,版本落后,基于SpringBoot2+,但支持JDK8/JDK11等旧JDK版本[https://github.com/moshowgame/SpringBootCodeGenerator/tree/jdk11]
6970

70-
7171
# 更新预告
7272
1.计划加入AI来帮忙生成更多样式的模板
7373
2.改进JSqlParser Engine (Select SQL and Create SQL)
7474

7575
# Update Logs
7676
| 更新日期 | 更新内容 |
7777
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
78+
| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL |
7879
| 2025.09.13 | JSqlParser Engine全新升级,目前Select SQL模式相对稳定! <br>更新SpringBoot等类库版本,修复漏洞<br>修复CDN问题,切换为staticfile.org |
7980
| 2025.03.31 | 优化说明 |
8081
| 2025.03.16 | NewUI V2前端优化:<br>移除不必要内容,优化Local和CDN静态文件引入。<br><br>修复由于SQL类型大写导致无法转换的问题。(感谢@zzy-design的反馈)<br><br>JPA模板优化(感谢@PenroseYang的反馈):<br>修复不开启Lombok情况下Set/Get方法生成问题;<br>修复importDdate判断为true后没有引入日期类的问题<br> |

generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,22 @@ public Map<String, String> getResultByParams(Map<String, Object> params) throws
8787
@Override
8888
public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
8989
ClassInfo classInfo = new ClassInfo();
90-
Statement statement = CCJSqlParserUtil.parse(paramInfo.getTableSql());
90+
String processedSql = paramInfo.getTableSql().trim()
91+
.replaceAll("'", "`") // 将单引号替换为反引号
92+
.replaceAll("\"", "`") // 将双引号替换为反引号
93+
.replaceAll(",", ","); // 将中文逗号替换为英文逗号
94+
95+
Statement statement = null;
9196
CCJSqlParserManager parserManager = new CCJSqlParserManager();
92-
statement = parserManager.parse(new StringReader(paramInfo.getTableSql()));
97+
statement = parserManager.parse(new StringReader(processedSql));
9398
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象
9499
List<String> tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表
95100
//一般这里应该只解析到一个表名,除非多个表名,取第一个
96101
if (!CollectionUtils.isEmpty(tableNameList)) {
97102
String tableName = tableNameList.get(0).trim();
98103
classInfo.setTableName(tableName);
99104
classInfo.setOriginTableName(tableName);
100-
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName));
105+
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)).replaceAll("`", "");
101106
if (className.contains("_")) {
102107
className = className.replaceAll("_", "");
103108
}
@@ -114,7 +119,7 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except
114119
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
115120
selectItems.forEach(t->{
116121
FieldInfo fieldInfo = new FieldInfo();
117-
String fieldName = ((Column)t.getExpression()).getColumnName();
122+
String fieldName = ((Column)t.getExpression()).getColumnName().replaceAll("`", "");
118123
String aliasName = t.getAlias() != null ? t.getAlias().getName() : ((Column)t.getExpression()).getColumnName();
119124
//存储原始字段名
120125
fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName);
@@ -153,8 +158,14 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except
153158
public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
154159
ClassInfo classInfo = new ClassInfo();
155160
Statement statement = null;
161+
// 对SQL进行预处理,以提高解析成功率
162+
String processedSql = paramInfo.getTableSql().trim()
163+
.replaceAll("'", "`") // 将单引号替换为反引号
164+
.replaceAll("\"", "`") // 将双引号替换为反引号
165+
.replaceAll(",", ","); // 将中文逗号替换为英文逗号
166+
156167
try {
157-
statement = CCJSqlParserUtil.parse(paramInfo.getTableSql().trim());
168+
statement = CCJSqlParserUtil.parse(processedSql);
158169
}catch (Exception e) {
159170
e.printStackTrace();
160171
throw new SqlException("SQL语法错误:"+e.getMessage());
@@ -166,7 +177,7 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except
166177
}
167178

168179
// 提取表名
169-
String tableName = createTable.getTable().getName();
180+
String tableName = createTable.getTable().getName().replaceAll("`", "");
170181
classInfo.setTableName(tableName);
171182
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName));
172183
if (className.contains("_")) {
@@ -183,7 +194,7 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except
183194
if (columnDefinitions != null) {
184195
for (ColumnDefinition columnDefinition : columnDefinitions) {
185196
FieldInfo fieldInfo = new FieldInfo();
186-
String columnName = columnDefinition.getColumnName();
197+
String columnName = columnDefinition.getColumnName().replaceAll("`", "");
187198
fieldInfo.setColumnName(columnName);
188199
fieldInfo.setFieldComment(columnDefinition.toString());
189200

generator-web/src/main/resources/application-bejson.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ OEM:
5353
header: SQL转Java JPA、MYBATIS实现类代码生成平台
5454
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
5555
title: JAVA在线代码生成
56-
slogan: Free your hands from tedious and repetitive CRUD work
57-
description: <p>SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。</p><p>——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。</p>
56+
slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
57+
description: <p>💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。</p><p>🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!</p><p>👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!</p>
5858
author: BEJSON.com
5959
packageName: www.bejson.com
60-
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow</a> + <a href="https://www.bejson.com/">BeJSON</a> , Might the holy light be with you !
60+
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow郑锴</a><a href="https://www.bejson.com/">BeJSON</a> — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻
6161
returnUtilSuccess: ResponseUtil.success
6262
returnUtilFailure: ResponseUtil.error
6363
outputStr: www.bejson.com

generator-web/src/main/resources/application-dev.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ OEM:
5050
version: 2025 September
5151
header: SQL转Java JPA、MYBATIS实现类代码生成平台
5252
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
53-
title: JAVA代码生成平台
54-
slogan: Free your hands from tedious and repetitive CRUD work
55-
description: <p>SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。</p><p>——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。</p>
53+
title: 大狼狗代码生成器
54+
slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
55+
description: <p>💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。</p><p>🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!</p><p>👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!</p>
5656
author: zhengkai.blog.csdn.net
5757
packageName: com.software.system
58-
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow郑锴</a> , Might the holy light be with you !
58+
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow郑锴</a> — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻
5959
returnUtilSuccess: ResponseUtil.success
6060
returnUtilFailure: ResponseUtil.error
6161
outputStr: http://zhengkai.blog.csdn.net

generator-web/src/main/resources/application-json.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ OEM:
5353
header: SQL转Java JPA、MYBATIS实现类代码生成平台
5454
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
5555
title: JAVA在线代码生成
56-
slogan: Free your hands from tedious and repetitive CRUD work
57-
description: <p>SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。</p><p>——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。</p>
56+
slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
57+
description: <p>💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。</p><p>🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!</p><p>👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!</p>
5858
author: https://www.json.cn/
5959
packageName: www.json.cn
60-
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow</a> + <a href="https://www.json.cn/">JSON</a> , Might the holy light be with you !
60+
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow郑锴</a><a href="https://www.json.cn/">JSON</a> — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻
6161
returnUtilSuccess: ResponseUtil.success
6262
returnUtilFailure: ResponseUtil.error
6363
outputStr: www.json.cn

generator-web/src/main/resources/templates/newui2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</div>
6363
<small>${(value.slogan)!!}</small>
6464
<div class="links">
65-
View in <a href="https://github.com/moshowgame/SpringBootCodeGenerator/" target="_blank">GitHub</a> <a href="https://gitee.com/moshowgame/SpringBootCodeGenerator/" target="_blank">Gitee</a>
65+
<a href="https://github.com/moshowgame/SpringBootCodeGenerator/" target="_blank">GitHub</a> <a href="https://zhengkai.blog.csdn.net/" target="_blank">CSDN</a>
6666
</div>
6767
</div>
6868
<div class="container">

0 commit comments

Comments
 (0)