| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL

This commit is contained in:
Moshow郑锴 2025-09-14 15:07:09 +08:00
parent f11a656a74
commit b687f3666b
6 changed files with 52 additions and 40 deletions

View File

@ -10,28 +10,29 @@
>powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net) >powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net)
# Description # Description
>The `Spring Boot Code Generator` , Based on SpringBoot3 and Freemarker<br> > 🚀 `Spring Boot Code Generator` — a powerful code generation platform built on SpringBoot3 & Freemarker
> #基于`SpringBoot3``Freemarker`的代码生成平台 > ✨ 基于 `SpringBoot3``Freemarker` 的高效代码生成平台
>
>Free your hands from tedious and repetitive CRUD work.<br> > 👐 Say goodbye to repetitive CRUD work — free your hands and boost productivity
> #解放你的双手摆脱繁琐重复的CRUD工作。 > 💡 告别繁琐重复的 CRUD 操作,释放你的双手,让开发更高效!
>
>Support mysql+oracle+pgsql , the most popular databases standard SQL<br> > 🛠️ Supports MySQL, Oracle, and PostgreSQL — the most popular SQL dialects
> #支持`MySQL`、Oracle、PgSQL三大主流数据库 > 📦 支持主流数据库:`MySQL``Oracle``PgSQL`,标准 SQL 一网打尽
>
>Generate various templates through table creation DDL statements, Insert SQL statements, Select SQL statements(*New), and simple JSON.<br> > ⚙️ Generate templates from DDL, INSERT SQL, SELECT SQL, or simple JSON — covering JPA, JdbcTemplate, Mybatis, MybatisPlus, BeetlSQL, CommonMapper
> 通过建表DDL语句、插入SQL语句、选择SQL语句*新以及简单JSON生成各种模板`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper`. > 🧩 通过建表 DDL、插入 SQL、选择 SQL 或简单 JSON一键生成 `JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper` 等模板代码
>
>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> > 🙏 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!
> 感谢大家的使用与反馈BeJSON上每天1.5K的PV访问量👀和 Github上2K的✨Stars是最大的鼓励与动力。 > ❤️ 感谢大家一直以来的支持BeJSON 曾创下日均访问量 1.5K 👀 的高峰,目前稳定在约 600 左右GitHub Star 数也已突破 2K ✨。你们的反馈始终是我们不断前进的最大动力!
>
>May everyone maintain a work-life balance, stay healthy and safe. Wishing you all success in your work and continuous advancements!. <br> > 🌈 Wishing everyone balance, health, and success — may your code be bug-free and your coffee strong ☕
> 愿大家可以维持生活和工作平衡,保持健康和安全,祝大家工作顺利,步步高升! > 💬 祝大家工作顺利,生活平衡,身体健康,步步高升,代码无 bug咖啡够劲
>
>Welcome to submit your issue and useful templates , or put your good idea into PR <br> > 📬 Feel free to submit issues, share useful templates, or contribute your brilliant ideas via PR
> 欢迎提交你的问题和常用有用模板或者提交你的好主意到PR。 > 🤝 欢迎提交问题、分享常用模板,或将你的灵感通过 PR 实现!
> 🙌 Special thanks to BeJSON 前站长 `三叔` 的慧眼与支持,让项目得以脱颖而出,感恩!
> 特别感谢BeJSON前站长`三叔`的慧眼和支持,让该项目得以脱颖而出,谢谢!
# URL # URL
@ -67,7 +68,6 @@
- Master主力分支基于SpringBoot3+需要JDK17+ - Master主力分支基于SpringBoot3+需要JDK17+
- JDK11兼容分支版本落后基于SpringBoot2+但支持JDK8/JDK11等旧JDK版本[https://github.com/moshowgame/SpringBootCodeGenerator/tree/jdk11] - JDK11兼容分支版本落后基于SpringBoot2+但支持JDK8/JDK11等旧JDK版本[https://github.com/moshowgame/SpringBootCodeGenerator/tree/jdk11]
# 更新预告 # 更新预告
1.计划加入AI来帮忙生成更多样式的模板 1.计划加入AI来帮忙生成更多样式的模板
2.改进JSqlParser Engine (Select SQL and Create SQL) 2.改进JSqlParser Engine (Select SQL and Create SQL)
@ -75,6 +75,7 @@
# Update Logs # Update Logs
| 更新日期 | 更新内容 | | 更新日期 | 更新内容 |
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 2025.09.14 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL |
| 2025.09.13 | JSqlParser Engine全新升级目前Select SQL模式相对稳定! <br>更新SpringBoot等类库版本修复漏洞<br>修复CDN问题切换为staticfile.org | | 2025.09.13 | JSqlParser Engine全新升级目前Select SQL模式相对稳定! <br>更新SpringBoot等类库版本修复漏洞<br>修复CDN问题切换为staticfile.org |
| 2025.03.31 | 优化说明 | | 2025.03.31 | 优化说明 |
| 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> | | 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> |

View File

@ -87,9 +87,14 @@ public class GeneratorServiceImpl implements GeneratorService {
@Override @Override
public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception { public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
ClassInfo classInfo = new ClassInfo(); ClassInfo classInfo = new ClassInfo();
Statement statement = CCJSqlParserUtil.parse(paramInfo.getTableSql()); String processedSql = paramInfo.getTableSql().trim()
.replaceAll("'", "`") // 将单引号替换为反引号
.replaceAll("\"", "`") // 将双引号替换为反引号
.replaceAll("", ","); // 将中文逗号替换为英文逗号
Statement statement = null;
CCJSqlParserManager parserManager = new CCJSqlParserManager(); CCJSqlParserManager parserManager = new CCJSqlParserManager();
statement = parserManager.parse(new StringReader(paramInfo.getTableSql())); statement = parserManager.parse(new StringReader(processedSql));
TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象 TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象
List<String> tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表 List<String> tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表
//一般这里应该只解析到一个表名除非多个表名取第一个 //一般这里应该只解析到一个表名除非多个表名取第一个
@ -97,7 +102,7 @@ public class GeneratorServiceImpl implements GeneratorService {
String tableName = tableNameList.get(0).trim(); String tableName = tableNameList.get(0).trim();
classInfo.setTableName(tableName); classInfo.setTableName(tableName);
classInfo.setOriginTableName(tableName); classInfo.setOriginTableName(tableName);
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)).replaceAll("`", "");
if (className.contains("_")) { if (className.contains("_")) {
className = className.replaceAll("_", ""); className = className.replaceAll("_", "");
} }
@ -114,7 +119,7 @@ public class GeneratorServiceImpl implements GeneratorService {
List<FieldInfo> fieldList = new ArrayList<FieldInfo>(); List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
selectItems.forEach(t->{ selectItems.forEach(t->{
FieldInfo fieldInfo = new FieldInfo(); FieldInfo fieldInfo = new FieldInfo();
String fieldName = ((Column)t.getExpression()).getColumnName(); String fieldName = ((Column)t.getExpression()).getColumnName().replaceAll("`", "");
String aliasName = t.getAlias() != null ? t.getAlias().getName() : ((Column)t.getExpression()).getColumnName(); String aliasName = t.getAlias() != null ? t.getAlias().getName() : ((Column)t.getExpression()).getColumnName();
//存储原始字段名 //存储原始字段名
fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName); fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName);
@ -153,8 +158,14 @@ public class GeneratorServiceImpl implements GeneratorService {
public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception { public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception {
ClassInfo classInfo = new ClassInfo(); ClassInfo classInfo = new ClassInfo();
Statement statement = null; Statement statement = null;
// 对SQL进行预处理以提高解析成功率
String processedSql = paramInfo.getTableSql().trim()
.replaceAll("'", "`") // 将单引号替换为反引号
.replaceAll("\"", "`") // 将双引号替换为反引号
.replaceAll("", ","); // 将中文逗号替换为英文逗号
try { try {
statement = CCJSqlParserUtil.parse(paramInfo.getTableSql().trim()); statement = CCJSqlParserUtil.parse(processedSql);
}catch (Exception e) { }catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw new SqlException("SQL语法错误:"+e.getMessage()); throw new SqlException("SQL语法错误:"+e.getMessage());
@ -166,7 +177,7 @@ public class GeneratorServiceImpl implements GeneratorService {
} }
// 提取表名 // 提取表名
String tableName = createTable.getTable().getName(); String tableName = createTable.getTable().getName().replaceAll("`", "");
classInfo.setTableName(tableName); classInfo.setTableName(tableName);
String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName));
if (className.contains("_")) { if (className.contains("_")) {
@ -183,7 +194,7 @@ public class GeneratorServiceImpl implements GeneratorService {
if (columnDefinitions != null) { if (columnDefinitions != null) {
for (ColumnDefinition columnDefinition : columnDefinitions) { for (ColumnDefinition columnDefinition : columnDefinitions) {
FieldInfo fieldInfo = new FieldInfo(); FieldInfo fieldInfo = new FieldInfo();
String columnName = columnDefinition.getColumnName(); String columnName = columnDefinition.getColumnName().replaceAll("`", "");
fieldInfo.setColumnName(columnName); fieldInfo.setColumnName(columnName);
fieldInfo.setFieldComment(columnDefinition.toString()); fieldInfo.setFieldComment(columnDefinition.toString());

View File

@ -53,11 +53,11 @@ OEM:
header: SQL转Java JPA、MYBATIS实现类代码生成平台 header: SQL转Java JPA、MYBATIS实现类代码生成平台
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
title: JAVA在线代码生成 title: JAVA在线代码生成
slogan: Free your hands from tedious and repetitive CRUD work slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
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> 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>
author: BEJSON.com author: BEJSON.com
packageName: www.bejson.com packageName: www.bejson.com
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 ! 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! ⚡🧙‍♂️💻
returnUtilSuccess: ResponseUtil.success returnUtilSuccess: ResponseUtil.success
returnUtilFailure: ResponseUtil.error returnUtilFailure: ResponseUtil.error
outputStr: www.bejson.com outputStr: www.bejson.com

View File

@ -50,12 +50,12 @@ OEM:
version: 2025 September version: 2025 September
header: SQL转Java JPA、MYBATIS实现类代码生成平台 header: SQL转Java JPA、MYBATIS实现类代码生成平台
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
title: JAVA代码生成平台 title: 大狼狗代码生成器
slogan: Free your hands from tedious and repetitive CRUD work slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
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> 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>
author: zhengkai.blog.csdn.net author: zhengkai.blog.csdn.net
packageName: com.software.system packageName: com.software.system
copyright: Powered by <a href="https://zhengkai.blog.csdn.net" target="_blank">Moshow郑锴</a> , Might the holy light be with you ! 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! ⚡🧙‍♂️💻
returnUtilSuccess: ResponseUtil.success returnUtilSuccess: ResponseUtil.success
returnUtilFailure: ResponseUtil.error returnUtilFailure: ResponseUtil.error
outputStr: http://zhengkai.blog.csdn.net outputStr: http://zhengkai.blog.csdn.net

View File

@ -53,11 +53,11 @@ OEM:
header: SQL转Java JPA、MYBATIS实现类代码生成平台 header: SQL转Java JPA、MYBATIS实现类代码生成平台
keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现
title: JAVA在线代码生成 title: JAVA在线代码生成
slogan: Free your hands from tedious and repetitive CRUD work slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡
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> 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>
author: https://www.json.cn/ author: https://www.json.cn/
packageName: www.json.cn packageName: www.json.cn
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 ! 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! ⚡🧙‍♂️💻
returnUtilSuccess: ResponseUtil.success returnUtilSuccess: ResponseUtil.success
returnUtilFailure: ResponseUtil.error returnUtilFailure: ResponseUtil.error
outputStr: www.json.cn outputStr: www.json.cn

View File

@ -62,7 +62,7 @@
</div> </div>
<small>${(value.slogan)!!}</small> <small>${(value.slogan)!!}</small>
<div class="links"> <div class="links">
View in <a href="https://github.com/moshowgame/SpringBootCodeGenerator/" target="_blank">GitHub</a> <a href="https://gitee.com/moshowgame/SpringBootCodeGenerator/" target="_blank">Gitee</a> <a href="https://github.com/moshowgame/SpringBootCodeGenerator/" target="_blank">GitHub</a> <a href="https://zhengkai.blog.csdn.net/" target="_blank">CSDN</a>
</div> </div>
</div> </div>
<div class="container"> <div class="container">