Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1a6e1a3

Browse files
| 2024年12月23日 | 新增InsertSQL模式,采用JSQLParser引擎进行封装<br>优化代码封装<br>CDN恢复为staticfile.org加速(如果本地卡的话,建议切换local模式)。<br>
1 parent ea4e612 commit 1a6e1a3

File tree

19 files changed

+778
-650
lines changed

19 files changed

+778
-650
lines changed

‎README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,31 @@
1010
>powered by `Moshow郑锴(大狼狗)` , [https://zhengkai.blog.csdn.net](https://zhengkai.blog.csdn.net)
1111
1212
# Description
13-
>Based on SpringBoot2+Freemarker<br>
14-
> #基于`SpringBoot2``Freemarker`的代码生成平台
13+
>The `Spring Boot Code Generator` , Based on SpringBoot3 and Freemarker<br>
14+
> #基于`SpringBoot3``Freemarker`的代码生成平台
1515
>
16-
>For reducing the repetitive CRUD work<br>
17-
> #以解放双手为目的,减少大量的`重复CRUD工作`
16+
>Release your hands from tedious and repetitive CRUD tasks.<br>
17+
> #从繁琐重复的`CRUD工作`中释放你的双手
1818
>
19-
>Support mysql, oracle and pgsql<br>
19+
>Support mysql+oracle+pgsql , the most popular databases standard SQL<br>
2020
> #支持`MySQL`、Oracle、PgSQL三大主流数据库
2121
>
22-
>Generate to many predefined popular templates by DDL-SQL/Insert-SQL/Simple JSON<br>
23-
> 可通过`建表SQL语句``INSERT语句`或者`简单JSON`生成预设的`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper`相关模板代码.
22+
>Generate various templates through table creation DDL statements, InsertSQL statements, Select SQL statements(*New), and simple JSON.<br>
23+
> 通过建表DDL语句、插入SQL语句、选择SQL语句(*新)以及简单JSON生成各种模板`JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL/CommonMapper`.
2424
>
25-
>Thanks for your using and feedback,I'm inspired by the 1500+PV (AVG) every day and github more than 1.9K stars <br>
26-
> 感谢大家的使用和反馈,每天1500的PV和获得超过九百多的星星是我前进和继续做下去的动力
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是最大的鼓励与动力
2727
>
28-
>Hope everyone can keep good balance on work and life , stay health and safety . I wish you success in your new position and get promoted step by step. <br>
28+
>May everyone maintain a work-life balance, stay healthy and safe. Wishing you all success in your work and continuous advancements!. <br>
2929
> 愿大家可以维持生活和工作平衡,保持健康和安全,祝大家工作顺利,步步高升!
30-
>Please submit your issue and template , or pull your good idea into the PR <br>
31-
> 提交你的问题和生成模板,或者提交你的好主意到PR。
30+
>
31+
>Welcome to submit your issue and useful templates , or put your good idea into PR <br>
32+
> 欢迎提交你的问题和常用有用模板,或者提交你的好主意到PR。
3233
3334

3435
# URL
3536

36-
- 感谢`卡卡`将他部署在[BEJSON](https://java.bejson.com/generator)上,目前是besjon专供的`金牌工具`(线上版本不一定是最新的,会有延迟,请谅解,谢谢).<br>
37+
- 感谢`卡卡`将他部署在[BEJSON](https://java.bejson.com/generator)上,目前是BeJSON专供的`金牌工具`(线上版本不一定是最新的,会有延迟,请谅解,谢谢).<br>
3738
- 感谢`jully.top`部署的副本 [https://jully.top/generator/](https://jully.top/generator/)。<br>
3839
- 感谢`BootCDN`提供稳定、快速、免费的前端开源项目 CDN 加速服务
3940
- Thanks for `JetBrains` providing us the `Licenses for Open Source Development` ,[Get free access to all JetBrains tools for developing your open source project!](https://www.jetbrains.com/community/opensource/#support) .<br>
@@ -49,7 +50,7 @@
4950
| GITHUB仓库 | https://github.com/moshowgame/SpringBootCodeGenerator |
5051

5152
# Tips or Features
52-
- 支持`DDL SQL`/`INSERT SQL`/`SIMPLE JSON`三种生成模式
53+
- 支持`DDL SQL`/`INSERT SQL`/`SIMPLE JSON`/`SELECT SQL`(*New)四种生成模式
5354
- `自动记忆`最近生成的内容,最多保留9个
5455
- 提供众多`通用模板`,易于使用,复制粘贴加简单修改即可完成CRUD操作
5556
- 支持`特殊字符`模板(`#`请用``代替;`$`请用`\`代替)
@@ -72,11 +73,12 @@
7273
# Update Logs
7374
| 更新日期 | 更新内容 |
7475
|:-----------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75-
| 2024年04月23日 | 切换为更快更稳定的BootCDN进行加速。<br>前端NEWUI改版(基于AdminLTE+Bootstrap+Vue+ElementUI混合模式)。|
76-
| 2024年04月22日 | [Java CI with Maven](https://github.com/moshowgame/SpringBootCodeGenerator/actions/workflows/maven.yml) 更新<br>SpringBoot升级到3.2.5<br>FastJSON升级到FastJSON2.0.49|
77-
| 2024年04月21日 | 推出JDK11分支,支持JDK8/JDK11/JDK17等版本,兼容性较好但维护速度较慢,为了更好兼容旧机器和旧环境|
78-
| 2024年04月20日 | 修复CDN版本cdn.staticfile.org域名备份失败问题,已同步更新到cdn.staticfile.net(本地版本则不受影响)|
79-
| 2024年01月26日 | 修复大写下滑线列名转驼峰问题(感谢@Nisus-Liu的PR)|
76+
| 2024年12月23日 | 新增InsertSQL模式,采用JSQLParser引擎进行封装<br>优化代码封装<br>CDN恢复为staticfile.org加速(如果本地卡的话,建议切换local模式)。<br> |
77+
| 2024年04月23日 | 切换为更快更稳定的BootCDN进行加速。<br>前端NEWUI改版(基于AdminLTE+Bootstrap+Vue+ElementUI混合模式)。 |
78+
| 2024年04月22日 | [Java CI with Maven](https://github.com/moshowgame/SpringBootCodeGenerator/actions/workflows/maven.yml) 更新<br>SpringBoot升级到3.2.5<br>FastJSON升级到FastJSON2.0.49 |
79+
| 2024年04月21日 | 推出JDK11分支,支持JDK8/JDK11/JDK17等版本,兼容性较好但维护速度较慢,为了更好兼容旧机器和旧环境 |
80+
| 2024年04月20日 | 修复CDN版本cdn.staticfile.org域名备份失败问题,已同步更新到cdn.staticfile.net(本地版本则不受影响) |
81+
| 2024年01月26日 | 修复大写下滑线列名转驼峰问题(感谢@Nisus-Liu的PR) |
8082
| 2023年10月22日 | 工具站CDN更新。 |
8183
| 2023年08月31日 | (感谢@Nisus-Liu的PR)<br>fix 驼峰列名转命名风格错误问题<br>增强转下划线命名风格, 对原始风格不敏感. 支持各种命名风格的列名 to 下划线<br>增加 NonCaseString 大小写不敏感字符串包装类, 简化编码<br>几点代码小优化。 |
8284
| 2023年07月11日 | 安全更新,正式支持SpringBoot3,javax升级到jakarta。 |
@@ -181,6 +183,8 @@
181183
- 当项目从2.7.x的springboot升级到3.0.x的时候,遇到一个问题"java: 程序包javax.servlet.http不存在" 问题:
182184
[java: 程序包javax.servlet.http不存在](https://zhengkai.blog.csdn.net/article/details/131362304)
183185

186+
- [CSDN【SpringBoot2启示录】专栏](https://blog.csdn.net/moshowgame/category_9274885.html)
187+
184188
2024 NEWUI版本
185189
<img src="./newui_version.png">
186190
2021 半Vue半JS版本

‎generator-web/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@
4646
<groupId>org.springframework.boot</groupId>
4747
<artifactId>spring-boot-autoconfigure</artifactId>
4848
</dependency>
49-
</dependencies>
49+
<dependency>
50+
<groupId>org.projectlombok</groupId>
51+
<artifactId>lombok</artifactId>
52+
<version>1.18.32</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
</dependencies>
5056

5157

5258
<build>

‎generator-web/src/main/java/com/softdev/system/generator/controller/GeneratorController.java

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.softdev.system.generator.util.TableParseUtil;
99
import com.softdev.system.generator.util.ValueUtil;
1010
import lombok.extern.slf4j.Slf4j;
11+
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
12+
import net.sf.jsqlparser.statement.Statement;
1113
import org.apache.commons.lang3.StringUtils;
1214
import org.springframework.beans.factory.annotation.Autowired;
1315
import org.springframework.stereotype.Controller;
@@ -56,26 +58,36 @@ public ReturnT generateCode(@RequestBody ParamInfo paramInfo) throws Exception {
5658
if (StringUtils.isEmpty(paramInfo.getTableSql())) {
5759
return ReturnT.error("表结构信息为空");
5860
}
59-
6061
//1.Parse Table Structure 表结构解析
6162
ClassInfo classInfo = null;
6263
String dataType = MapUtil.getString(paramInfo.getOptions(),"dataType");
63-
if ("sql".equals(dataType)||dataType==null) {
64-
classInfo = TableParseUtil.processTableIntoClassInfo(paramInfo);
65-
}else if ("json".equals(dataType)) {
66-
//JSON模式:parse field from json string
67-
classInfo = TableParseUtil.processJsonToClassInfo(paramInfo);
68-
//INSERT SQL模式:parse field from insert sql
69-
} else if ("insert-sql".equals(dataType)) {
70-
classInfo = TableParseUtil.processInsertSqlToClassInfo(paramInfo);
71-
//正则表达式模式(非完善版本):parse sql by regex
72-
} else if ("sql-regex".equals(dataType)) {
73-
classInfo = TableParseUtil.processTableToClassInfoByRegex(paramInfo);
74-
//默认模式:default parse sql by java
64+
switch (dataType) {
65+
case "sql":
66+
//默认模式:parse DDL table structure from sql
67+
classInfo = generatorService.processTableIntoClassInfo(paramInfo);
68+
break;
69+
case "json":
70+
//JSON模式:parse field from json string
71+
classInfo = generatorService.processJsonToClassInfo(paramInfo);
72+
break;
73+
case "insert-sql":
74+
//INSERT SQL模式:parse field from insert sql
75+
classInfo = generatorService.processInsertSqlToClassInfo(paramInfo);
76+
break;
77+
case "sql-regex":
78+
//正则表达式模式(非完善版本):parse sql by regex
79+
classInfo = generatorService.processTableToClassInfoByRegex(paramInfo);
80+
break;
81+
case "select-sql":
82+
//SelectSqlBySQLPraser模式:parse select sql by JSqlParser
83+
classInfo = generatorService.generateSelectSqlBySQLPraser(paramInfo);
84+
break;
85+
default:
86+
//默认模式:parse DDL table structure from sql
87+
classInfo = generatorService.processTableIntoClassInfo(paramInfo);
88+
break;
7589
}
76-
7790
//2.Set the params 设置表格参数
78-
7991
paramInfo.getOptions().put("classInfo", classInfo);
8092
paramInfo.getOptions().put("tableName", classInfo == null ? System.currentTimeMillis() : classInfo.getTableName());
8193

‎generator-web/src/main/java/com/softdev/system/generator/entity/ParamInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class ParamInfo {
1717

1818
@Data
1919
public static class NAME_CASE_TYPE {
20-
public static String CAMEL_CASE = "CamelCase";
21-
public static String UNDER_SCORE_CASE = "UnderScoreCase";
22-
public static String UPPER_UNDER_SCORE_CASE = "UpperUnderScoreCase";
20+
public static finalString CAMEL_CASE = "CamelCase";
21+
public static finalString UNDER_SCORE_CASE = "UnderScoreCase";
22+
public static finalString UPPER_UNDER_SCORE_CASE = "UpperUnderScoreCase";
2323
}
2424

2525
}

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.softdev.system.generator.service;
22

3+
import com.softdev.system.generator.entity.ClassInfo;
4+
import com.softdev.system.generator.entity.ParamInfo;
35
import freemarker.template.TemplateException;
46
import org.springframework.stereotype.Service;
57

@@ -15,6 +17,40 @@ public interface GeneratorService {
1517

1618
String getTemplateConfig() throws IOException;
1719

18-
public Map<String, String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException;
19-
20+
Map<String, String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException;
21+
/**
22+
* 解析Select-SQL生成类信息(JSQLPraser版本)
23+
* @auther: zhengkai.blog.csdn.net
24+
* @param paramInfo
25+
* @return
26+
*/
27+
ClassInfo generateSelectSqlBySQLPraser(ParamInfo paramInfo) throws Exception;
28+
/**
29+
* 解析DDL-SQL生成类信息
30+
* @auther: zhengkai.blog.csdn.net
31+
* @param paramInfo
32+
* @return
33+
*/
34+
ClassInfo processTableIntoClassInfo(ParamInfo paramInfo) throws Exception;
35+
/**
36+
* 解析JSON生成类信息
37+
* @auther: zhengkai.blog.csdn.net
38+
* @param paramInfo
39+
* @return
40+
*/
41+
ClassInfo processJsonToClassInfo(ParamInfo paramInfo);
42+
/**
43+
* 解析DDL SQL生成类信息-正则表达式版本
44+
* @auther: zhengkai.blog.csdn.net
45+
* @param paramInfo
46+
* @return
47+
*/
48+
ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo);
49+
/**
50+
* 解析INSERT-SQL生成类信息-正则表达式版本
51+
* @auther: zhengkai.blog.csdn.net
52+
* @param paramInfo
53+
* @return
54+
*/
55+
ClassInfo processInsertSqlToClassInfo(ParamInfo paramInfo);
2056
}

0 commit comments

Comments
(0)

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