mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
20200503:1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理<br> 2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈) 3.修优化对所有类型的判断(感谢@cnlw的反馈) 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 5.升级hutool和lombok版本
This commit is contained in:
parent
0dea9b5ac0
commit
77748195dd
@ -27,6 +27,7 @@
|
||||
|
||||
|更新日期|更新内容|
|
||||
|-|-|
|
||||
|20200503|1.优化对特殊字符的处理,对于包含#和$等特殊字符的,在模板使用井和¥代替便可,escapeString方法会自动处理<br> 2.优化mybatisplus实体类相关(感谢@chunchengmeigui的反馈) 3.修优化对所有类型的判断(感谢@cnlw的反馈) 4.移除swagger-entity,该功能已经包含在‘swagger-ui’的下拉选项中 5.升级hutool和lombok版本|
|
||||
|20200306|1.提交一套layuimini+mybatisplus的模板. 2.修复mybatisplus一些相关问题. |
|
||||
|20200206|1.新增历史记录功能,自动保存最近生成的对象 2.新增swagger开关选项和修复@Column带name参数(感谢@liuyu-struggle的建议) 3.去除mybatis模板中的方括号[]和修改模板里的类注释样式(感谢@gaohanghang的PR)|
|
||||
|20191229|1.修复bejson安全防护策略拦截问题(感谢@liangbintao和@1808083642的反馈) 2.优化字段名含date字符串的处理(感谢@smilexzh的反馈) 3.控制台动态输出项目访问地址(感谢@gaohanghang的提交)|
|
||||
|
||||
@ -49,11 +49,11 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
//beetsql
|
||||
result.put("beetlmd", freemarkerTool.processString("code-generator/beetlsql/beetlmd.ftl", params));
|
||||
result.put("beetlentity", freemarkerTool.processString("code-generator/beetlsql/beetlentity.ftl", params));
|
||||
result.put("beetlentitydto", freemarkerTool.processString("code-generator/beetlsql/beetlentitydto.ftl", params));
|
||||
result.put("beetlcontroller", freemarkerTool.processString("code-generator/beetlsql/beetlcontroller.ftl", params));
|
||||
//mybatis plus
|
||||
result.put("pluscontroller", freemarkerTool.processString("code-generator/mybatis-plus/pluscontroller.ftl", params));
|
||||
result.put("plusmapper", freemarkerTool.processString("code-generator/mybatis-plus/plusmapper.ftl", params));
|
||||
result.put("plusentity", freemarkerTool.processString("code-generator/mybatis-plus/plusentity.ftl", params));
|
||||
//util
|
||||
result.put("util", freemarkerTool.processString("code-generator/util/util.ftl", params));
|
||||
result.put("json", freemarkerTool.processString("code-generator/util/json.ftl", params));
|
||||
|
||||
@ -37,7 +37,13 @@ public class FreemarkerTool {
|
||||
template.process(model, result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 传入需要转义的字符串进行转义
|
||||
* 20200503 zhengkai.blog.csdn.net
|
||||
* */
|
||||
public String escapeString(String originStr){
|
||||
return originStr.replaceAll("井","\\#").replaceAll("¥","\\$");
|
||||
}
|
||||
/**
|
||||
* process String
|
||||
*
|
||||
@ -49,9 +55,10 @@ public class FreemarkerTool {
|
||||
*/
|
||||
public String processString(String templateName, Map<String, Object> params)
|
||||
throws IOException, TemplateException {
|
||||
|
||||
//获取对应的模板
|
||||
Template template = configuration.getTemplate(templateName);
|
||||
String htmlText = processTemplateIntoString(template, params);
|
||||
//处理为template并进行转义
|
||||
String htmlText = escapeString(processTemplateIntoString(template, params));
|
||||
return htmlText;
|
||||
}
|
||||
|
||||
|
||||
@ -194,20 +194,25 @@ public class TableParseUtil {
|
||||
String fieldClass = Object.class.getSimpleName();
|
||||
//2018-9-16 zhengk 补充char/clob/blob/json等类型,如果类型未知,默认为String
|
||||
//2018-11-22 lshz0088 处理字段类型的时候,不严谨columnLine.contains(" int") 类似这种的,可在前后适当加一些空格之类的加以区分,否则当我的字段包含这些字符的时候,产生类型判断问题。
|
||||
if (columnLine.contains(" int") || columnLine.contains("smallint")) {
|
||||
//2020-05-03 MOSHOW.K.ZHENG 优化对所有类型的处理
|
||||
if (columnLine.contains(" tinyint") ) {
|
||||
//20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
|
||||
fieldClass=tinyintTransType;
|
||||
}
|
||||
else if (columnLine.contains(" int") || columnLine.contains(" smallint")) {
|
||||
fieldClass = Integer.class.getSimpleName();
|
||||
} else if (columnLine.contains("bigint")) {
|
||||
} else if (columnLine.contains(" bigint")) {
|
||||
fieldClass = Long.class.getSimpleName();
|
||||
} else if (columnLine.contains("float")) {
|
||||
} else if (columnLine.contains(" float")) {
|
||||
fieldClass = Float.class.getSimpleName();
|
||||
} else if (columnLine.contains("double")) {
|
||||
} else if (columnLine.contains(" double")) {
|
||||
fieldClass = Double.class.getSimpleName();
|
||||
} else if (columnLine.contains("time") || columnLine.contains(" date") || columnLine.contains("datetime") || columnLine.contains("timestamp")) {
|
||||
} else if (columnLine.contains(" time") || columnLine.contains(" date") || columnLine.contains(" datetime") || columnLine.contains(" timestamp")) {
|
||||
fieldClass = Date.class.getSimpleName();
|
||||
} else if (columnLine.contains("varchar") || columnLine.contains(" text")|| columnLine.contains("char")
|
||||
|| columnLine.contains("clob")||columnLine.contains("blob")||columnLine.contains("json")) {
|
||||
} else if (columnLine.contains(" varchar") || columnLine.contains(" text")|| columnLine.contains(" char")
|
||||
|| columnLine.contains(" clob")||columnLine.contains(" blob")||columnLine.contains(" json")) {
|
||||
fieldClass = String.class.getSimpleName();
|
||||
} else if (columnLine.contains("decimal")||columnLine.contains(" number")) {
|
||||
} else if (columnLine.contains(" decimal")||columnLine.contains(" number")) {
|
||||
//2018-11-22 lshz0088 建议对number类型增加int,long,BigDecimal的区分判断
|
||||
//如果startKh大于等于0,则表示有设置取值范围
|
||||
int startKh=columnLine.indexOf("(");
|
||||
@ -239,12 +244,9 @@ public class TableParseUtil {
|
||||
}else{
|
||||
fieldClass = BigDecimal.class.getSimpleName();
|
||||
}
|
||||
} else if (columnLine.contains("boolean")) {
|
||||
} else if (columnLine.contains(" boolean")) {
|
||||
//20190910 MOSHOW.K.ZHENG 新增对boolean的处理(感谢@violinxsc的反馈)以及修复tinyint类型字段无法生成boolean类型问题(感谢@hahaYhui的反馈)
|
||||
fieldClass = Boolean.class.getSimpleName();
|
||||
} else if (columnLine.contains("tinyint") ) {
|
||||
//20191115 MOSHOW.K.ZHENG 支持对tinyint的特殊处理
|
||||
fieldClass=tinyintTransType;
|
||||
} else {
|
||||
fieldClass = String.class.getSimpleName();
|
||||
}
|
||||
|
||||
14
generator-web/src/main/resources/rebel.xml
Normal file
14
generator-web/src/main/resources/rebel.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!--
|
||||
This is the JRebel configuration file. It maps the running application to your IDE workspace, enabling JRebel reloading for this project.
|
||||
Refer to https://manuals.jrebel.com/jrebel/standalone/config.html for more information.
|
||||
-->
|
||||
<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">
|
||||
|
||||
<classpath>
|
||||
<dir name="E:/workspace/idea with spring/SpringBootCodeGenerator/generator-web/target/classes">
|
||||
</dir>
|
||||
</classpath>
|
||||
|
||||
</application>
|
||||
@ -8,7 +8,8 @@ import java.util.List;
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Data
|
||||
@Data<#if swagger?exists && swagger==true>
|
||||
@ApiModel("${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -17,7 +18,8 @@ public class ${classInfo.className} implements Serializable {
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/
|
||||
*/<#if swagger?exists && swagger==true>
|
||||
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("${classInfo.classComment}")
|
||||
public class ${classInfo.className}DTO {
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@ApiModelProperty("${fieldItem.fieldComment}")
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package ${packageName}.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.io.Serializable;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
||||
/**
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Data
|
||||
<#if swagger?exists && swagger==true>@ApiModel("${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/<#if swagger?exists && swagger==true>
|
||||
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
public ${classInfo.className}() {
|
||||
}
|
||||
</#if>
|
||||
|
||||
}
|
||||
@ -2,6 +2,7 @@ package ${packageName}.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
|
||||
/**
|
||||
@ -12,6 +13,25 @@ import ${packageName}.entity.${classInfo.className};
|
||||
@Mapper
|
||||
public interface ${classInfo.className}Mapper extends BaseMapper<${classInfo.className}> {
|
||||
|
||||
@Select(
|
||||
"<script>select t0.* from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
//add here if need page limit
|
||||
//" limit ¥{page},¥{limit} " +
|
||||
" </script>")
|
||||
List<${classInfo.className}> pageAll(${classInfo.className} queryParamDTO);
|
||||
|
||||
@Select("<script>select count(1) from ${classInfo.tableName} t0 " +
|
||||
//add here if need left join
|
||||
"where 1=1" +
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
"<when test='${fieldItem.fieldName}!=null and ${fieldItem.fieldName}!='' '> and t0.${fieldItem.columnName}=井{${fieldItem.fieldName}}</when> " +
|
||||
</#list>
|
||||
" </script>")
|
||||
int countAll(${classInfo.className} queryParamDTO);
|
||||
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<link rel="stylesheet" href="request.contextPath/static/lib/layui-v2.5.5/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="request.contextPath/static/css/public.css" media="all">
|
||||
<link rel="stylesheet" href="¥{request.contextPath}/static/lib/layui-v2.5.5/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="¥{request.contextPath}/static/css/public.css" media="all">
|
||||
<style>
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
@ -38,7 +38,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="request.contextPath/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script src="¥{request.contextPath}/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script>
|
||||
layui.use(['form'], function () {
|
||||
var form = layui.form,
|
||||
@ -49,7 +49,7 @@
|
||||
form.on('submit(saveBtn)', function (data) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "request.contextPath/${classInfo.className?uncap_first}/save",
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/save",
|
||||
data:JSON.stringify(data.field),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
|
||||
@ -6,8 +6,8 @@
|
||||
<meta name="renderer" content="webkit">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
||||
<link rel="stylesheet" href="request.contextPath/static/lib/layui-v2.5.5/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="request.contextPath/static/css/public.css" media="all">
|
||||
<link rel="stylesheet" href="¥{request.contextPath}/static/lib/layui-v2.5.5/css/layui.css" media="all">
|
||||
<link rel="stylesheet" href="¥{request.contextPath}/static/css/public.css" media="all">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layuimini-container">
|
||||
@ -25,7 +25,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">${classInfo.classComment}Name</label>
|
||||
<label class="layui-form-label">${classInfo.classComment}名称</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="${classInfo.className?uncap_first}Name" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
@ -41,7 +41,7 @@
|
||||
<script type="text/html" id="toolbarDemo">
|
||||
<div class="layui-btn-container">
|
||||
<button class="layui-btn layui-btn-sm data-add-btn"> 添加${classInfo.classComment} </button>
|
||||
<button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"> 删除${classInfo.classComment} </button>
|
||||
<#-- <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn"> 删除${classInfo.classComment} </button>-->
|
||||
</div>
|
||||
</script>
|
||||
|
||||
@ -61,7 +61,7 @@
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<script src="request.contextPath/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script src="¥{request.contextPath}/static/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
|
||||
<script>
|
||||
layui.use(['form', 'table'], function () {
|
||||
var $ = layui.jquery,
|
||||
@ -72,7 +72,7 @@
|
||||
table.render({
|
||||
elem: '#currentTableId',
|
||||
method: 'post',
|
||||
url: 'request.contextPath/${classInfo.className?uncap_first}/list',
|
||||
url: '¥{request.contextPath}/${classInfo.className?uncap_first}/list',
|
||||
toolbar: '#toolbarDemo',
|
||||
defaultToolbar: ['filter', 'exports', 'print', {
|
||||
title: '提示',
|
||||
@ -88,8 +88,8 @@
|
||||
</#if>
|
||||
{title: '操作', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
|
||||
]],
|
||||
limits: [5, 20, 50 , 100],
|
||||
limit: 5,
|
||||
limits: [10, 20, 50 , 100],
|
||||
limit: 10,
|
||||
page: true
|
||||
});
|
||||
|
||||
@ -123,12 +123,9 @@
|
||||
maxmin:true,
|
||||
shadeClose: true,
|
||||
area: ['800px', '500px'],
|
||||
content: 'request.contextPath/${classInfo.className?uncap_first}/edit?id=0',
|
||||
});
|
||||
$(window).on("resize", function () {
|
||||
obj.del();
|
||||
layer.full(index);
|
||||
content: '¥{request.contextPath}/${classInfo.className?uncap_first}/edit?id=0',
|
||||
});
|
||||
layer.full(index);
|
||||
return false;
|
||||
});
|
||||
|
||||
@ -149,24 +146,21 @@
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') {
|
||||
var index = layer.open({
|
||||
title: '编辑用户',
|
||||
title: '编辑${classInfo.classComment}',
|
||||
type: 2,
|
||||
shade: 0.2,
|
||||
maxmin:true,
|
||||
shadeClose: true,
|
||||
area: ['800px', '500px'],
|
||||
content: 'request.contextPath/${classInfo.className?uncap_first}/edit?id='+obj.data.${classInfo.className?uncap_first}Id,
|
||||
});
|
||||
$(window).on("resize", function () {
|
||||
obj.del();
|
||||
layer.full(index);
|
||||
content: '¥{request.contextPath}/${classInfo.className?uncap_first}/edit?id='+obj.data.${classInfo.className?uncap_first}Id,
|
||||
});
|
||||
layer.full(index);
|
||||
return false;
|
||||
} else if (obj.event === 'delete') {
|
||||
layer.confirm('真的删除行么', function (index) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "request.contextPath/${classInfo.className?uncap_first}/delete",
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/delete",
|
||||
data:{"id":obj.data.${classInfo.className?uncap_first}Id},
|
||||
success: function (responseData) {
|
||||
if (responseData.code === 200) {
|
||||
|
||||
@ -324,6 +324,7 @@ CREATE TABLE 'userinfo' (
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group" role="group" aria-label="First group">
|
||||
<button type="button" class="btn btn-default generator" id="plusentity">entity</button>
|
||||
<button type="button" class="btn btn-default generator" id="plusmapper">mapper</button>
|
||||
<button type="button" class="btn btn-default generator" id="pluscontroller">controller</button>
|
||||
</div>
|
||||
@ -397,16 +398,6 @@ CREATE TABLE 'userinfo' (
|
||||
</div>
|
||||
</div>
|
||||
<div class="row" style="margin-top: 10px;">
|
||||
<div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<div class="btn btn-secondary disabled setWidth" id="btnGroupAddon">DTO</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group" role="group" aria-label="First group">
|
||||
<button type="button" class="btn btn-default generator" id="beetlentitydto">entitydto(lombok+swagger)</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
|
||||
6
pom.xml
6
pom.xml
@ -79,14 +79,14 @@
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.0.6</version>
|
||||
<version>5.3.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- lombok -->
|
||||
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.8</version>
|
||||
<version>1.18.12</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user