Skip to content

Commit 3316c98

Browse files
authored
Merge pull request #8 from moshowgame/master
merge
2 parents 9b6562b + 7774819 commit 3316c98

File tree

17 files changed

+462
-93
lines changed

17 files changed

+462
-93
lines changed

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Moshow K ZHENG(Moshow/郑锴/大狼狗)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
|更新日期|更新内容|
2929
|-|-|
30+
|20200503|1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理<br> 2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈) 3.修优化对所有类型的判断(感谢@cnlw的反馈) 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 5.升级hutool和lombok版本|
31+
|20200306|1.提交一套layuimini+mybatisplus的模板. 2.修复mybatisplus一些相关问题. |
3032
|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)|
3133
|20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)|
3234
|20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) |

generator-web/src/main/java/com/softdev/system/generator/config/ServerConfig.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,14 @@
1515
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
1616

1717
private int serverPort;
18-
19-
public int getPort() {
20-
return this.serverPort;
21-
}
18+
private String serverPath;
2219

2320
@Override
2421
public void onApplicationEvent(WebServerInitializedEvent event) {
2522
this.serverPort = event.getWebServer().getPort();
26-
//log.info("Get WebServer port {}", serverPort);
27-
log.info("项目启动启动成功!访问地址: http://localhost:{}/generator", serverPort);
23+
//新增动态path by zhengkai
24+
this.serverPath = event.getApplicationContext().getApplicationName();
25+
log.info("项目启动启动成功!访问地址: http://localhost:{}{}", serverPort,serverPath);
2826
}
2927

3028
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public Map<String, String> getResultByParams(Map<String, Object> params) throws
3030
result.put("swagger-ui", freemarkerTool.processString("code-generator/ui/swagger-ui.ftl", params));
3131
result.put("element-ui", freemarkerTool.processString("code-generator/ui/element-ui.ftl", params));
3232
result.put("bootstrap-ui", freemarkerTool.processString("code-generator/ui/bootstrap-ui.ftl", params));
33+
result.put("layui-edit", freemarkerTool.processString("code-generator/ui/layui-edit.ftl", params));
34+
result.put("layui-list", freemarkerTool.processString("code-generator/ui/layui-list.ftl", params));
3335
//mybatis old
3436
result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params));
3537
result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params));
@@ -47,11 +49,11 @@ public Map<String, String> getResultByParams(Map<String, Object> params) throws
4749
//beetsql
4850
result.put("beetlmd", freemarkerTool.processString("code-generator/beetlsql/beetlmd.ftl", params));
4951
result.put("beetlentity", freemarkerTool.processString("code-generator/beetlsql/beetlentity.ftl", params));
50-
result.put("beetlentitydto", freemarkerTool.processString("code-generator/beetlsql/beetlentitydto.ftl", params));
5152
result.put("beetlcontroller", freemarkerTool.processString("code-generator/beetlsql/beetlcontroller.ftl", params));
5253
//mybatis plus
5354
result.put("pluscontroller", freemarkerTool.processString("code-generator/mybatis-plus/pluscontroller.ftl", params));
5455
result.put("plusmapper", freemarkerTool.processString("code-generator/mybatis-plus/plusmapper.ftl", params));
56+
result.put("plusentity", freemarkerTool.processString("code-generator/mybatis-plus/plusentity.ftl", params));
5557
//util
5658
result.put("util", freemarkerTool.processString("code-generator/util/util.ftl", params));
5759
result.put("json", freemarkerTool.processString("code-generator/util/json.ftl", params));

generator-web/src/main/java/com/softdev/system/generator/util/FreemarkerTool.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public String processTemplateIntoString(Template template, Object model)
3737
template.process(model, result);
3838
return result.toString();
3939
}
40-
40+
/**
41+
* 传入需要转义的字符串进行转义
42+
* 20200503 zhengkai.blog.csdn.net
43+
* */
44+
public String escapeString(String originStr){
45+
return originStr.replaceAll("井","\\#").replaceAll("¥","\\$");
46+
}
4147
/**
4248
* process String
4349
*
@@ -49,9 +55,10 @@ public String processTemplateIntoString(Template template, Object model)
4955
*/
5056
public String processString(String templateName, Map<String, Object> params)
5157
throws IOException, TemplateException {
52-
58+
//获取对应的模板
5359
Template template = configuration.getTemplate(templateName);
54-
String htmlText = processTemplateIntoString(template, params);
60+
//处理为template并进行转义
61+
String htmlText = escapeString(processTemplateIntoString(template, params));
5562
return htmlText;
5663
}
5764

generator-web/src/main/java/com/softdev/system/generator/util/TableParseUtil.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,25 @@ public static ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
194194
String fieldClass = Object.class.getSimpleName();
195195
//2018-9-16 zhengk 补充char/clob/blob/json等类型,如果类型未知,默认为String
196196
//2018-11-22 lshz0088 处理字段类型的时候,不严谨columnLine.contains(" int") 类似这种的,可在前后适当加一些空格之类的加以区分,否则当我的字段包含这些字符的时候,产生类型判断问题。
197-
if (columnLine.contains(" int") || columnLine.contains("smallint")) {
197+
//2020-05-03 MOSHOW.K.ZHENG 优化对所有类型的处理
198+
if (columnLine.contains(" tinyint") ) {
199+
//20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
200+
fieldClass=tinyintTransType;
201+
}
202+
else if (columnLine.contains(" int") || columnLine.contains(" smallint")) {
198203
fieldClass = Integer.class.getSimpleName();
199-
} else if (columnLine.contains("bigint")) {
204+
} else if (columnLine.contains(" bigint")) {
200205
fieldClass = Long.class.getSimpleName();
201-
} else if (columnLine.contains("float")) {
206+
} else if (columnLine.contains(" float")) {
202207
fieldClass = Float.class.getSimpleName();
203-
} else if (columnLine.contains("double")) {
208+
} else if (columnLine.contains(" double")) {
204209
fieldClass = Double.class.getSimpleName();
205-
} else if (columnLine.contains("time") || columnLine.contains(" date") || columnLine.contains("datetime") || columnLine.contains("timestamp")) {
210+
} else if (columnLine.contains(" time") || columnLine.contains(" date") || columnLine.contains(" datetime") || columnLine.contains(" timestamp")) {
206211
fieldClass = Date.class.getSimpleName();
207-
} else if (columnLine.contains("varchar") || columnLine.contains(" text")|| columnLine.contains("char")
208-
|| columnLine.contains("clob")||columnLine.contains("blob")||columnLine.contains("json")) {
212+
} else if (columnLine.contains(" varchar") || columnLine.contains(" text")|| columnLine.contains(" char")
213+
|| columnLine.contains(" clob")||columnLine.contains(" blob")||columnLine.contains(" json")) {
209214
fieldClass = String.class.getSimpleName();
210-
} else if (columnLine.contains("decimal")||columnLine.contains(" number")) {
215+
} else if (columnLine.contains(" decimal")||columnLine.contains(" number")) {
211216
//2018-11-22 lshz0088 建议对number类型增加int,long,BigDecimal的区分判断
212217
//如果startKh大于等于0,则表示有设置取值范围
213218
int startKh=columnLine.indexOf("(");
@@ -239,12 +244,9 @@ public static ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
239244
}else{
240245
fieldClass = BigDecimal.class.getSimpleName();
241246
}
242-
} else if (columnLine.contains("boolean")) {
247+
} else if (columnLine.contains(" boolean")) {
243248
//20190910 MOSHOW.K.ZHENG 新增对boolean的处理(感谢@violinxsc的反馈)以及修复tinyint类型字段无法生成boolean类型问题(感谢@hahaYhui的反馈)
244249
fieldClass = Boolean.class.getSimpleName();
245-
} else if (columnLine.contains("tinyint") ) {
246-
//20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
247-
fieldClass=tinyintTransType;
248250
} else {
249251
fieldClass = String.class.getSimpleName();
250252
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!--
4+
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
5+
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
6+
-->
7+
<application generated-by="intellij" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.zeroturnaround.com" xsi:schemaLocation="http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_1.xsd">
8+
9+
<classpath>
10+
<dir name="E:/workspace/idea with spring/SpringBootCodeGenerator/generator-web/target/classes">
11+
</dir>
12+
</classpath>
13+
14+
</application>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version": "20200206"}
1+
{"version": "20200306"}

generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentity.ftl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import java.util.List;
88
* @author ${authorName}
99
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
1010
*/
11-
@Data
11+
@Data<#if swagger?exists && swagger==true>
12+
@ApiModel("${classInfo.classComment}")</#if>
1213
public class ${classInfo.className} implements Serializable {
1314

1415
private static final long serialVersionUID = 1L;
@@ -17,7 +18,8 @@ public class ${classInfo.className} implements Serializable {
1718
<#list classInfo.fieldList as fieldItem >
1819
/**
1920
* ${fieldItem.fieldComment}
20-
*/
21+
*/<#if swagger?exists && swagger==true>
22+
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
2123
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
2224

2325
</#list>

generator-web/src/main/resources/templates/code-generator/beetlsql/beetlentitydto.ftl

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)