From 995e1e608a1fb5f413eec817848766893ab00dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: 2025年9月14日 00:40:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?JSqlParser=20Engine=E5=85=A8=E6=96=B0?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=EF=BC=8C=E7=9B=AE=E5=89=8DSelect=20SQL?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E7=9B=B8=E5=AF=B9=E7=A8=B3=E5=AE=9A!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +- .../controller/GeneratorController.java | 2 +- .../service/GeneratorServiceImpl.java | 122 ++++++++---------- .../system/generator/util/SqlException.java | 35 +++++ .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application.yml | 2 +- .../src/main/resources/statics/js/main.js | 5 +- .../src/main/resources/templates/newui2.html | 2 +- 8 files changed, 100 insertions(+), 75 deletions(-) create mode 100644 generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java diff --git a/README.md b/README.md index 13db9f93..54a1949f 100644 --- a/README.md +++ b/README.md @@ -70,13 +70,12 @@ # 更新预告 1.计划加入AI来帮忙生成更多样式的模板 -2.计划使用AI来改善现有模板 -3.深度支持Select SQL模式,以及探索JSON模式更多可能 +2.改进JSqlParser Engine (Select SQL and Create SQL) # Update Logs | 更新日期 | 更新内容 | |:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| 2025年09月13日 | Create SQL by JSqlParser Engine升级
更新SpringBoot等类库版本,修复漏洞
修复CDN问题,切换为staticfile.org | +| 2025年09月13日 | JSqlParser Engine全新升级,目前Select SQL模式相对稳定!
更新SpringBoot等类库版本,修复漏洞
修复CDN问题,切换为staticfile.org | | 2025年03月31日 | 优化说明 | | 2025年03月16日 | NewUI V2前端优化:
移除不必要内容,优化Local和CDN静态文件引入。

修复由于SQL类型大写导致无法转换的问题。(感谢@zzy-design的反馈)

JPA模板优化(感谢@PenroseYang的反馈):
修复不开启Lombok情况下Set/Get方法生成问题;
修复importDdate判断为true后没有引入日期类的问题
| | 2024年12月29日 | 优化前端加载速度,优化输出代码着色,CDN改字节跳动静态资源公共库。
| 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 index caa967d1..3a9142bb 100644 --- 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 @@ -88,7 +88,7 @@ public ReturnT generateCode(@RequestBody ParamInfo paramInfo) throws Exception { classInfo = generatorService.generateSelectSqlBySQLPraser(paramInfo); break; case "create-sql": - //SelectSqlBySQLPraser模式:parse select sql by JSqlParser + //CreateSqlBySQLPraser模式:parse create sql by JSqlParser classInfo = generatorService.generateCreateSqlBySQLPraser(paramInfo); break; default: diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java index b4658c42..e6ec491f 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java +++ b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java @@ -96,6 +96,7 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except if (!CollectionUtils.isEmpty(tableNameList)) { String tableName = tableNameList.get(0).trim(); classInfo.setTableName(tableName); + classInfo.setOriginTableName(tableName); String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); if (className.contains("_")) { className = className.replaceAll("_", ""); @@ -121,21 +122,15 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except fieldName=fieldName.contains(".")?fieldName.substring(fieldName.indexOf(".")+1):fieldName; //转换前 fieldInfo.setColumnName(fieldName); - switch ((String) paramInfo.getOptions().get("nameCaseType")) { - case ParamInfo.NAME_CASE_TYPE.CAMEL_CASE: + fieldName = switch ((String) paramInfo.getOptions().get("nameCaseType")) { + case ParamInfo.NAME_CASE_TYPE.CAMEL_CASE -> // 2024年1月27日 L&J 适配任意(maybe)原始风格转小写驼峰 - fieldName = StringUtilsPlus.toLowerCamel(aliasName); - break; - case ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE: - fieldName = StringUtilsPlus.toUnderline(aliasName, false); - break; - case ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE: - fieldName = StringUtilsPlus.toUnderline(aliasName.toUpperCase(), true); - break; - default: - fieldName = aliasName; - break; - } + StringUtilsPlus.toLowerCamel(aliasName); + case ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE -> StringUtilsPlus.toUnderline(aliasName, false); + case ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE -> + StringUtilsPlus.toUnderline(aliasName.toUpperCase(), true); + default -> aliasName; + }; //转换后 fieldInfo.setFieldName(fieldName); @@ -157,62 +152,57 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except @Override public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception { ClassInfo classInfo = new ClassInfo(); - Statement statement = CCJSqlParserUtil.parse(paramInfo.getTableSql()); - CCJSqlParserManager parserManager = new CCJSqlParserManager(); - statement = parserManager.parse(new StringReader(paramInfo.getTableSql())); - TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象 - List tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表 - //一般这里应该只解析到一个表名,除非多个表名,取第一个 - if (!CollectionUtils.isEmpty(tableNameList)) { - String tableName = tableNameList.get(0).trim(); - classInfo.setTableName(tableName); - String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); - if (className.contains("_")) { - className = className.replaceAll("_", ""); - } - classInfo.setClassName(className); - classInfo.setClassComment(paramInfo.getTableSql()); + Statement statement = null; + try { + statement = CCJSqlParserUtil.parse(paramInfo.getTableSql().trim()); + }catch (Exception e) { + e.printStackTrace(); + throw new SqlException("SQL语法错误:"+e.getMessage()); } - //解析查询元素 - Select select = null; - select = (Select) CCJSqlParserUtil.parse(paramInfo.getTableSql()); - PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); - List> selectItems = plainSelect.getSelectItems(); - // field List + // 确保是CREATE TABLE语句 + if (!(statement instanceof CreateTable createTable)) { + throw new SqlException("检测到SQL语句不是DLL CREATE TABLE语句"); + } + + // 提取表名 + String tableName = createTable.getTable().getName(); + classInfo.setTableName(tableName); + String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); + if (className.contains("_")) { + className = className.replaceAll("_", ""); + } + classInfo.setClassName(className); + classInfo.setOriginTableName(tableName); + classInfo.setClassComment(paramInfo.getTableSql()); + + // 提取字段信息 List fieldList = new ArrayList(); - selectItems.forEach(t->{ - FieldInfo fieldInfo = new FieldInfo(); - String fieldName = ((Column)t.getExpression()).getColumnName(); - String aliasName = t.getAlias() != null ? t.getAlias().getName() : ((Column)t.getExpression()).getColumnName(); - //存储原始字段名 - fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName); - //处理字段名是t.xxx的情况 - fieldName=fieldName.contains(".")?fieldName.substring(fieldName.indexOf(".")+1):fieldName; - //转换前 - fieldInfo.setColumnName(fieldName); - switch ((String) paramInfo.getOptions().get("nameCaseType")) { - case ParamInfo.NAME_CASE_TYPE.CAMEL_CASE: - // 2024年1月27日 L&J 适配任意(maybe)原始风格转小写驼峰 - fieldName = StringUtilsPlus.toLowerCamel(aliasName); - break; - case ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE: - fieldName = StringUtilsPlus.toUnderline(aliasName, false); - break; - case ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE: - fieldName = StringUtilsPlus.toUnderline(aliasName.toUpperCase(), true); - break; - default: - fieldName = aliasName; - break; + List columnDefinitions = createTable.getColumnDefinitions(); + + if (columnDefinitions != null) { + for (ColumnDefinition columnDefinition : columnDefinitions) { + FieldInfo fieldInfo = new FieldInfo(); + String columnName = columnDefinition.getColumnName(); + fieldInfo.setColumnName(columnName); + fieldInfo.setFieldComment(columnDefinition.toString()); + + // 根据命名规则转换字段名 + 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 -> + StringUtilsPlus.toUnderline(columnName.toUpperCase(), true); + default -> columnName; + }; + fieldInfo.setFieldName(fieldName); + + // 设置字段类型为String(因为无法准确推测类型) + fieldInfo.setFieldClass("String"); + fieldList.add(fieldInfo); } - //转换后 - fieldInfo.setFieldName(fieldName); - - //无法推测类型,所有都set为String - fieldInfo.setFieldClass("String"); - fieldList.add(fieldInfo); - }); + } + classInfo.setFieldList(fieldList); log.info("classInfo:{}", JSON.toJSONString(classInfo)); return classInfo; diff --git a/generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java b/generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java new file mode 100644 index 00000000..de6ccdbd --- /dev/null +++ b/generator-web/src/main/java/com/softdev/system/generator/util/SqlException.java @@ -0,0 +1,35 @@ +package com.softdev.system.generator.util; + +import java.io.Serial; + +/** + * @author xuxueli 2018年05月02日 21:10:28 + */ +public class SqlException extends RuntimeException { + + @Serial + private static final long serialVersionUID = 42L; + + public SqlException() { + super(); + } + + public SqlException(String msg) { + super(msg); + } + + public SqlException(String msg, Throwable cause) { + super(msg, cause); + } + + public SqlException(Throwable cause) { + super(cause); + } + + public SqlException(String message, Throwable cause, + boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + +} diff --git a/generator-web/src/main/resources/application-dev.yml b/generator-web/src/main/resources/application-dev.yml index e7c6fc19..de3c2375 100644 --- a/generator-web/src/main/resources/application-dev.yml +++ b/generator-web/src/main/resources/application-dev.yml @@ -59,4 +59,4 @@ OEM: returnUtilSuccess: ResponseUtil.success returnUtilFailure: ResponseUtil.error outputStr: http://zhengkai.blog.csdn.net - mode: CDN + mode: local diff --git a/generator-web/src/main/resources/application.yml b/generator-web/src/main/resources/application.yml index 6857c9dc..caf4dfcd 100644 --- a/generator-web/src/main/resources/application.yml +++ b/generator-web/src/main/resources/application.yml @@ -1,3 +1,3 @@ spring: profiles: - active: bejson \ No newline at end of file + active: dev \ No newline at end of file diff --git a/generator-web/src/main/resources/statics/js/main.js b/generator-web/src/main/resources/statics/js/main.js index 101b56f5..e714a1ac 100644 --- a/generator-web/src/main/resources/statics/js/main.js +++ b/generator-web/src/main/resources/statics/js/main.js @@ -123,8 +123,9 @@ const vm = new Vue({ //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语句!!!"); + if(res.status===500||res.data.code===500){ + console.log(res); + error("生成失败,请检查SQL语句!!!"+res.data.msg); return; } setAllCookie(); diff --git a/generator-web/src/main/resources/templates/newui2.html b/generator-web/src/main/resources/templates/newui2.html index be1da789..a831a67e 100644 --- a/generator-web/src/main/resources/templates/newui2.html +++ b/generator-web/src/main/resources/templates/newui2.html @@ -100,7 +100,7 @@
生成设置
- + From aeb5427d285d924bb6fd88ce0bd7a850cdced356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: 2025年9月14日 13:50:40 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B8=85=E7=90=86,=20rem?= =?UTF-8?q?ove=20demised=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GeneratorController.java | 8 - .../src/main/resources/templates/index.html | 124 ---------- .../src/main/resources/templates/main-v2.html | 234 ------------------ 3 files changed, 366 deletions(-) delete mode 100644 generator-web/src/main/resources/templates/index.html delete mode 100644 generator-web/src/main/resources/templates/main-v2.html 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 index 3a9142bb..44f788f2 100644 --- 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 @@ -41,14 +41,6 @@ public ModelAndView defaultPage() { public ModelAndView indexPage() { return new ModelAndView("newui2").addObject("value",valueUtil); } - @GetMapping("/newui2") - public ModelAndView newui2() { - return new ModelAndView("newui2").addObject("value",valueUtil); - } - @GetMapping("/main") - public ModelAndView mainPage() { - return new ModelAndView("main").addObject("value",valueUtil); - } @RequestMapping("/template/all") @ResponseBody diff --git a/generator-web/src/main/resources/templates/index.html b/generator-web/src/main/resources/templates/index.html deleted file mode 100644 index 8701ce7e..00000000 --- a/generator-web/src/main/resources/templates/index.html +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - <#include "/header.html"> - ${(value.title)!!} - -

${(value.title)!!}

-
- - - - - - -
- - - -
-
-
- - -
- -
- ${(value.description)!!} -
- - - <#include "/main-v2.html"> -
- -
- -
-
- -
- - - - - - - - -
- - - -

AltStyle によって変換されたページ (->オリジナル) /

- diff --git a/generator-web/src/main/resources/templates/main-v2.html b/generator-web/src/main/resources/templates/main-v2.html deleted file mode 100644 index 2cf65cb3..00000000 --- a/generator-web/src/main/resources/templates/main-v2.html +++ /dev/null @@ -1,234 +0,0 @@ - - - - <#include "/header.html"> - - - - -
-
- -
-
-
输入SQL
-
- - -
-
-
- - - -
-
- -
-
-
-
生成设置
-
- - -
-
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- -
-
-
- - 生成 - 复制 -
- - -
-
-
- - - - - 历史记录 - - {{item}} - - - - -
-
-
-
-
-
模板选择
-
- - -
-
-
- - -
- - {{item.group}} - - {{childItem.name}} - - -
- -
- -
-
- - -
-
-
-
输出代码
-
- - -
-
-
- - -
-
-
-
-
- - - - - \ No newline at end of file From f11a656a74f278999cc5e1d00036b6fbcd4d8c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: 2025年9月14日 13:54:19 +0800 Subject: [PATCH 3/5] Set Version to "2025 September" --- generator-web/src/main/resources/application-bejson.yml | 2 +- generator-web/src/main/resources/application-dev.yml | 2 +- generator-web/src/main/resources/application-json.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generator-web/src/main/resources/application-bejson.yml b/generator-web/src/main/resources/application-bejson.yml index fcf3ab88..d56a6f5f 100644 --- a/generator-web/src/main/resources/application-bejson.yml +++ b/generator-web/src/main/resources/application-bejson.yml @@ -49,7 +49,7 @@ spring: #mvc: # static-path-pattern: /statics/** OEM: - version: 2025 March + version: 2025 September header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 title: JAVA在线代码生成 diff --git a/generator-web/src/main/resources/application-dev.yml b/generator-web/src/main/resources/application-dev.yml index de3c2375..93c4bfff 100644 --- a/generator-web/src/main/resources/application-dev.yml +++ b/generator-web/src/main/resources/application-dev.yml @@ -47,7 +47,7 @@ spring: #mvc: # static-path-pattern: /statics/** OEM: - version: 2025 March + version: 2025 September header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 title: JAVA代码生成平台 diff --git a/generator-web/src/main/resources/application-json.yml b/generator-web/src/main/resources/application-json.yml index 6ed9c158..4838be47 100644 --- a/generator-web/src/main/resources/application-json.yml +++ b/generator-web/src/main/resources/application-json.yml @@ -49,7 +49,7 @@ spring: #mvc: # static-path-pattern: /statics/** OEM: - version: 2025 March + version: 2025 September header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 title: JAVA在线代码生成 From b687f3666b5f5dbe16aa82141873e16e7e99c9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: 2025年9月14日 15:07:09 +0800 Subject: [PATCH 4/5] =?UTF-8?q?|=202025.09.14=20|=20=E4=BC=98=E5=8C=96JSql?= =?UTF-8?q?Parser=20Engine(DDL=20Create=20SQL=E5=92=8CSelect=20SQL),?= =?UTF-8?q?=E9=80=82=E9=85=8D=E6=9B=B4=E9=AB=98=E7=BA=A7=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E7=9A=84SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 47 ++++++++++--------- .../service/GeneratorServiceImpl.java | 25 +++++++--- .../src/main/resources/application-bejson.yml | 6 +-- .../src/main/resources/application-dev.yml | 8 ++-- .../src/main/resources/application-json.yml | 6 +-- .../src/main/resources/templates/newui2.html | 2 +- 6 files changed, 53 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 54a1949f..361fab75 100644 --- a/README.md +++ b/README.md @@ -10,28 +10,29 @@ >powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net) # Description ->The `Spring Boot Code Generator` , Based on SpringBoot3 and Freemarker
-> #基于`SpringBoot3`和`Freemarker`的代码生成平台 -> ->Free your hands from tedious and repetitive CRUD work.
-> #解放你的双手,摆脱繁琐重复的CRUD工作。 -> ->Support mysql+oracle+pgsql , the most popular databases standard SQL
-> #支持`MySQL`、Oracle、PgSQL三大主流数据库 -> ->Generate various templates through table creation DDL statements, Insert SQL statements, Select SQL statements(*New), and simple JSON.
-> 通过建表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.
-> 感谢大家的使用与反馈,BeJSON上每天1.5K的PV访问量👀和 Github上2K的✨Stars是最大的鼓励与动力。 -> ->May everyone maintain a work-life balance, stay healthy and safe. Wishing you all success in your work and continuous advancements!.
-> 愿大家可以维持生活和工作平衡,保持健康和安全,祝大家工作顺利,步步高升! -> ->Welcome to submit your issue and useful templates , or put your good idea into PR
-> 欢迎提交你的问题和常用有用模板,或者提交你的好主意到PR。 - -> 特别感谢BeJSON前站长`三叔`的慧眼和支持,让该项目得以脱颖而出,谢谢! +> 🚀 `Spring Boot Code Generator` — a powerful code generation platform built on SpringBoot3 & Freemarker +> ✨ 基于 `SpringBoot3` 和 `Freemarker` 的高效代码生成平台 + +> 👐 Say goodbye to repetitive CRUD work — free your hands and boost productivity +> 💡 告别繁琐重复的 CRUD 操作,释放你的双手,让开发更高效! + +> 🛠️ Supports MySQL, Oracle, and PostgreSQL — the most popular SQL dialects +> 📦 支持主流数据库:`MySQL`、`Oracle`、`PgSQL`,标准 SQL 一网打尽 + +> ⚙️ 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` 等模板代码 + +> 🙏 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 👀 的高峰,目前稳定在约 600 左右,GitHub Star 数也已突破 2K ✨。你们的反馈始终是我们不断前进的最大动力! + +> 🌈 Wishing everyone balance, health, and success — may your code be bug-free and your coffee strong ☕ +> 💬 祝大家工作顺利,生活平衡,身体健康,步步高升,代码无 bug,咖啡够劲! + +> 📬 Feel free to submit issues, share useful templates, or contribute your brilliant ideas via PR +> 🤝 欢迎提交问题、分享常用模板,或将你的灵感通过 PR 实现! + +> 🙌 Special thanks to BeJSON 前站长 `三叔` 的慧眼与支持,让项目得以脱颖而出,感恩! + # URL @@ -67,7 +68,6 @@ - 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) @@ -75,6 +75,7 @@ # Update Logs | 更新日期 | 更新内容 | |:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| 2025年09月14日 | 优化JSqlParser Engine(DDL Create SQL和Select SQL),适配更高级复杂的SQL | | 2025年09月13日 | JSqlParser Engine全新升级,目前Select SQL模式相对稳定!
更新SpringBoot等类库版本,修复漏洞
修复CDN问题,切换为staticfile.org | | 2025年03月31日 | 优化说明 | | 2025年03月16日 | NewUI V2前端优化:
移除不必要内容,优化Local和CDN静态文件引入。

修复由于SQL类型大写导致无法转换的问题。(感谢@zzy-design的反馈)

JPA模板优化(感谢@PenroseYang的反馈):
修复不开启Lombok情况下Set/Get方法生成问题;
修复importDdate判断为true后没有引入日期类的问题
| diff --git a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java index e6ec491f..de98dbd5 100644 --- a/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java +++ b/generator-web/src/main/java/com/softdev/system/generator/service/GeneratorServiceImpl.java @@ -87,9 +87,14 @@ public Map getResultByParams(Map params) throws @Override public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception { 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(); - statement = parserManager.parse(new StringReader(paramInfo.getTableSql())); + statement = parserManager.parse(new StringReader(processedSql)); TablesNamesFinder tablesNamesFinder = new TablesNamesFinder(); // 创建表名发现者对象 List tableNameList = tablesNamesFinder.getTableList(statement); // 获取到表名列表 //一般这里应该只解析到一个表名,除非多个表名,取第一个 @@ -97,7 +102,7 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except String tableName = tableNameList.get(0).trim(); classInfo.setTableName(tableName); classInfo.setOriginTableName(tableName); - String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); + String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)).replaceAll("`", ""); if (className.contains("_")) { className = className.replaceAll("_", ""); } @@ -114,7 +119,7 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except List fieldList = new ArrayList(); selectItems.forEach(t->{ 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(); //存储原始字段名 fieldInfo.setFieldComment(aliasName);fieldInfo.setColumnName(aliasName); @@ -153,8 +158,14 @@ public ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Except public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Exception { ClassInfo classInfo = new ClassInfo(); Statement statement = null; + // 对SQL进行预处理,以提高解析成功率 + String processedSql = paramInfo.getTableSql().trim() + .replaceAll("'", "`") // 将单引号替换为反引号 + .replaceAll("\"", "`") // 将双引号替换为反引号 + .replaceAll(",", ","); // 将中文逗号替换为英文逗号 + try { - statement = CCJSqlParserUtil.parse(paramInfo.getTableSql().trim()); + statement = CCJSqlParserUtil.parse(processedSql); }catch (Exception e) { e.printStackTrace(); throw new SqlException("SQL语法错误:"+e.getMessage()); @@ -166,7 +177,7 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except } // 提取表名 - String tableName = createTable.getTable().getName(); + String tableName = createTable.getTable().getName().replaceAll("`", ""); classInfo.setTableName(tableName); String className = StringUtilsPlus.upperCaseFirst(StringUtilsPlus.underlineToCamelCase(tableName)); if (className.contains("_")) { @@ -183,7 +194,7 @@ public ClassInfo generateCreateSqlBySQLPraser(ParamInfo paramInfo) throws Except if (columnDefinitions != null) { for (ColumnDefinition columnDefinition : columnDefinitions) { FieldInfo fieldInfo = new FieldInfo(); - String columnName = columnDefinition.getColumnName(); + String columnName = columnDefinition.getColumnName().replaceAll("`", ""); fieldInfo.setColumnName(columnName); fieldInfo.setFieldComment(columnDefinition.toString()); diff --git a/generator-web/src/main/resources/application-bejson.yml b/generator-web/src/main/resources/application-bejson.yml index d56a6f5f..079aaf5b 100644 --- a/generator-web/src/main/resources/application-bejson.yml +++ b/generator-web/src/main/resources/application-bejson.yml @@ -53,11 +53,11 @@ OEM: header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 title: JAVA在线代码生成 - slogan: Free your hands from tedious and repetitive CRUD work - description:

SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。

——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。

+ slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡ + description:

💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。

🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!

👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!

author: BEJSON.com packageName: www.bejson.com - copyright: Powered by Moshow + BeJSON , Might the holy light be with you ! + copyright: ✨ Powered by Moshow郑锴BeJSON — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻 returnUtilSuccess: ResponseUtil.success returnUtilFailure: ResponseUtil.error outputStr: www.bejson.com diff --git a/generator-web/src/main/resources/application-dev.yml b/generator-web/src/main/resources/application-dev.yml index 93c4bfff..fdcf712b 100644 --- a/generator-web/src/main/resources/application-dev.yml +++ b/generator-web/src/main/resources/application-dev.yml @@ -50,12 +50,12 @@ OEM: version: 2025 September header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 - title: JAVA代码生成平台 - slogan: Free your hands from tedious and repetitive CRUD work - description:

SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。

——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。

+ title: 大狼狗代码生成器 + slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡ + description:

💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。

🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!

👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!

author: zhengkai.blog.csdn.net packageName: com.software.system - copyright: Powered by Moshow郑锴 , Might the holy light be with you ! + copyright: ✨ Powered by Moshow郑锴 — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻 returnUtilSuccess: ResponseUtil.success returnUtilFailure: ResponseUtil.error outputStr: http://zhengkai.blog.csdn.net diff --git a/generator-web/src/main/resources/application-json.yml b/generator-web/src/main/resources/application-json.yml index 4838be47..c1ccc0e3 100644 --- a/generator-web/src/main/resources/application-json.yml +++ b/generator-web/src/main/resources/application-json.yml @@ -53,11 +53,11 @@ OEM: header: SQL转Java JPA、MYBATIS实现类代码生成平台 keywords: sql转实体类,sql转DAO,SQL转service,SQL转JPA实现,SQL转MYBATIS实现 title: JAVA在线代码生成 - slogan: Free your hands from tedious and repetitive CRUD work - description:

SpringBootCodeGenerator,又名`大狼狗代码生成器`、`SQL转JAVA`、`SQL转JPA`、`SQL转Mybatis`、`Mybatis在线生成器`、`SQL转Java JPA、MYBATIS实现类代码生成平台`。

——从繁琐重复的`CRUD工作`中释放你的双手,可通过DDL SQL语句或Select SQL语句或简单Json -> 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper等相关模板代码。

+ slogan: 👐 Free your hands from boring CRUD—let the code write itself! ⚡ + description:

💻 SpringBootCodeGenerator,又名 `大狼狗代码生成器`🐺🐶,支持 SQL 一键转 JAVA/JPA/Mybatis/MybatisPlus 等多种模板,轻松搞定 CRUD,彻底解放双手 ✋!只需提供 DDL、SELECT SQL 或简单 JSON 👉 即可生成 生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper 等代码模板。

🔥🔥🔥 全新 JSqlParser 引擎上线,强力支持 DDL CREATE SQL与 SELECT SQL 解析!欢迎体验 & 反馈 💬!

👨‍💻 面向开发者的高效利器,已服务数万工程师,欢迎 Star ⭐、Fork 🍴、提 Issue 💬,一起打造更强大的代码生成平台!

author: https://www.json.cn/ packageName: www.json.cn - copyright: Powered by Moshow + JSON , Might the holy light be with you ! + copyright: ✨ Powered by Moshow郑锴JSON — may the holy light guide your code, your coffee, and your commits! ⚡🧙‍♂️💻 returnUtilSuccess: ResponseUtil.success returnUtilFailure: ResponseUtil.error outputStr: www.json.cn diff --git a/generator-web/src/main/resources/templates/newui2.html b/generator-web/src/main/resources/templates/newui2.html index a831a67e..93f5ee74 100644 --- a/generator-web/src/main/resources/templates/newui2.html +++ b/generator-web/src/main/resources/templates/newui2.html @@ -62,7 +62,7 @@
${(value.slogan)!!}
- View in GitHub Gitee + GitHub CSDN
From 74a4f3f29314f08ce2f1fe780743ccc0c8cc5bfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moshow=E9=83=91=E9=94=B4?= Date: 2025年9月14日 15:15:14 +0800 Subject: [PATCH 5/5] =?UTF-8?q?|=202025.09.06=20|=20=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=BB=BA=E8=A1=A8=E5=AD=97=E6=AE=B5=E5=8C=85=E5=90=AB=20using?= =?UTF-8?q?=20=E5=AD=97=E7=AC=A6=E6=97=B6=E6=97=A0=E6=B3=95=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AF=B9=E5=BA=94=E5=AD=97=E6=AE=B5=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5(=E6=84=9F=E8=B0=A2@wubiaoo=E7=9A=84=E5=8F=8D=E9=A6=88?= =?UTF-8?q?=E5=92=8C@willxiang=E7=9A=84PR)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 361fab75..5c136b8d 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,7 @@ |:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 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) | | 2025年03月31日 | 优化说明 | | 2025年03月16日 | NewUI V2前端优化:
移除不必要内容,优化Local和CDN静态文件引入。

修复由于SQL类型大写导致无法转换的问题。(感谢@zzy-design的反馈)

JPA模板优化(感谢@PenroseYang的反馈):
修复不开启Lombok情况下Set/Get方法生成问题;
修复importDdate判断为true后没有引入日期类的问题
| | 2024年12月29日 | 优化前端加载速度,优化输出代码着色,CDN改字节跳动静态资源公共库。
|