Skip to content

Commit 2316fb1

Browse files
committed
1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@column带name参数(感谢@liuyu-struggle的建议)
1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@column带name参数(感谢@liuyu-struggle的建议)
1 parent 03152e5 commit 2316fb1

File tree

7 files changed

+75
-10
lines changed

7 files changed

+75
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
|更新日期|更新内容|
2929
|-|-|
30+
|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议)|
3031
|20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)|
3132
|20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) |
3233
|20191126|1.springboot2内置tomcat更换为性能更强大的undertow 2.修复tinyintTransType参数丢失问题 |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.softdev.system.generator.controller;
22

3+
import com.alibaba.fastjson.JSON;
34
import com.softdev.system.generator.entity.ClassInfo;
45
import com.softdev.system.generator.entity.ParamInfo;
56
import com.softdev.system.generator.entity.ReturnT;
@@ -60,9 +61,14 @@ public ReturnT<Map<String, String>> codeGenerate(@RequestBody ParamInfo paramInf
6061
// process the param
6162
Map<String, Object> params = new HashMap<String, Object>(8);
6263
params.put("classInfo", classInfo);
64+
params.put("tableName", classInfo==null?System.currentTimeMillis():classInfo.getTableName());
6365
params.put("authorName", paramInfo.getAuthorName());
6466
params.put("packageName", paramInfo.getPackageName());
6567
params.put("returnUtil", paramInfo.getReturnUtil());
68+
params.put("swagger", paramInfo.isSwagger());
69+
70+
//log the params
71+
//log.info(JSON.toJSONString(paramInfo));
6672

6773
log.info("generator table:"+(classInfo==null?"":classInfo.getTableName())
6874
+",field size:"+((classInfo==null||classInfo.getFieldList()==null)?"":classInfo.getFieldList().size()));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class ParamInfo {
1515
private String nameCaseType;
1616
private String tinyintTransType;
1717
private String dataType;
18+
private boolean swagger;
1819

1920
@Data
2021
public static class NAME_CASE_TYPE{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class GeneratorServiceImpl implements GeneratorService {
2525
public Map<String, String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException {
2626
// result
2727
Map<String, String> result = new HashMap<String, String>(32);
28-
28+
result.put("tableName",params.get("tableName")+"");
2929
//UI
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));
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version": "20191229"}
1+
{"version": "20200206"}

generator-web/src/main/resources/templates/code-generator/jpa/entity.ftl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import io.swagger.annotations.ApiModelProperty;
1818
*/
1919
@Entity
2020
@Data
21-
@Table(name="${classInfo.tableName}")
22-
@ApiModel("${classInfo.classComment}")
21+
@Table(name="${classInfo.tableName}")<#if swagger?exists && swagger==true>
22+
@ApiModel("${classInfo.classComment}")</#if>
2323
public class ${classInfo.className} implements Serializable {
2424

2525
private static final long serialVersionUID = 1L;
@@ -30,9 +30,9 @@ public class ${classInfo.className} implements Serializable {
3030
<#list classInfo.fieldList as fieldItem >
3131
/**
3232
* ${fieldItem.fieldComment}
33-
*/
34-
@ApiModelProperty("${fieldItem.fieldComment}")
35-
@Column("${fieldItem.columnName}")
33+
*/<#if swagger?exists && swagger==true>
34+
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
35+
@Column(name="${fieldItem.columnName}")
3636
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
3737

3838
</#list>

generator-web/src/main/resources/templates/index.ftl

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
});
6060
return o;
6161
};
62+
var historyCount=0;
63+
//初始化清除session
64+
if (window.sessionStorage){
65+
//修复当F5刷新的时候,session没有清空各个值,但是页面的button没了。
66+
sessionStorage.clear();
67+
}
6268
/**
6369
* 生成代码
6470
*/
@@ -70,7 +76,8 @@
7076
"authorName":$("#authorName").val(),
7177
"dataType":$("#dataType").val(),
7278
"tinyintTransType":$("#tinyintTransType").val(),
73-
"nameCaseType":$("#nameCaseType").val()
79+
"nameCaseType":$("#nameCaseType").val(),
80+
"swagger":$("#isSwagger").val()
7481
};
7582
$.ajax({
7683
type: 'POST',
@@ -81,16 +88,57 @@
8188
success: function (data) {
8289
if (data.code === 200) {
8390
codeData = data.data;
84-
genCodeArea.setValue(codeData.beetlentity);
91+
genCodeArea.setValue(codeData.entity);
8592
genCodeArea.setSize('auto', 'auto');
8693
$.toast("√ 代码生成成功");
94+
//添加历史记录
95+
addHistory(codeData);
8796
} else {
8897
$.toast("× 代码生成失败 :"+data.msg);
8998
}
9099
}
91100
});
92101
return false;
93102
});
103+
/**
104+
* 切换历史记录
105+
*/
106+
function getHistory(tableName){
107+
if (window.sessionStorage){
108+
var valueSession = sessionStorage.getItem(tableName);
109+
codeData = JSON.parse(valueSession);
110+
$.toast("$ 切换历史记录成功:"+tableName);
111+
genCodeArea.setValue(codeData.entity);
112+
}else{
113+
console.log("浏览器不支持sessionStorage");
114+
}
115+
}
116+
/**
117+
* 添加历史记录
118+
*/
119+
function addHistory(data){
120+
if (window.sessionStorage){
121+
//console.log(historyCount);
122+
if(historyCount>=9){
123+
$("#history").find(".btn:last").remove();
124+
historyCount--;
125+
}
126+
var tableName=data.tableName;
127+
var valueSession = sessionStorage.getItem(tableName);
128+
if(valueSession!==undefined && valueSession!=null){
129+
sessionStorage.removeItem(tableName);
130+
}else{
131+
$("#history").prepend('<button id="his-'+tableName+'" type="button" class="btn">'+tableName+'</button>');
132+
//$("#history").prepend('<button id="his-'+tableName+'" onclick="getHistory(\''+tableName+'\');" type="button" class="btn">'+tableName+'</button>');
133+
$("#his-"+tableName).bind('click', function () {getHistory(tableName)});
134+
}
135+
sessionStorage.setItem(tableName,JSON.stringify(data));
136+
historyCount++;
137+
}else{
138+
console.log("浏览器不支持sessionStorage");
139+
}
140+
}
141+
94142
/**
95143
* 按钮事件组
96144
*/
@@ -169,7 +217,7 @@
169217
<div class="container">
170218
<h2>Spring Boot Code Generator!</h2>
171219
<p class="lead">
172-
√基于SpringBoot2+Freemarker的代码生成器,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
220+
√基于SpringBoot2+Freemarker的<a class="lead" href="https://github.com/moshowgame/SpringBootCodeGenerator">代码生成器</a>,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
173221
√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码。<br>
174222
如果发现有SQL语句不能识别,请<a href="https://github.com/moshowgame/SpringBootCodeGenerator/issues">留言</a>,同时欢迎大家提<a href="https://github.com/moshowgame/SpringBootCodeGenerator/pulls">PR</a>和<a href="#" id="donate1">赞赏</a>,谢谢!<a id="version" href="#">查看版本</a>
175223
</p>
@@ -219,6 +267,14 @@
219267
<option value="UnderScoreCase">下划线</option>
220268
<#--<option value="UpperUnderScoreCase">大写下划线</option>-->
221269
</select>
270+
<div class="input-group-prepend">
271+
<span class="input-group-text">swagger-ui</span>
272+
</div>
273+
<select type="text" class="form-control" id="isSwagger"
274+
name="isSwagger">
275+
<option value="false">关闭</option>
276+
<option value="true">开启</option>
277+
</select>
222278
</div>
223279
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
224280
CREATE TABLE 'userinfo' (
@@ -229,6 +285,7 @@ CREATE TABLE 'userinfo' (
229285
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息'
230286
</textarea><br>
231287
<p><button class="btn btn-primary btn-lg disabled" id="btnGenCode" role="button" data-toggle="popover" data-content="">开始生成 »</button> <button class="btn alert-secondary" id="btnCopy">一键复制</button></p>
288+
<div id="history" class="btn-group" role="group" aria-label="Basic example"></div>
232289
<hr>
233290
<!-- Example row of columns -->
234291
<div class="row" style="margin-top: 10px;">

0 commit comments

Comments
 (0)