mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2026-05-08 14:26:18 +08:00
Compare commits
13 Commits
r20191128.
...
20200503
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77748195dd | ||
|
|
0dea9b5ac0 | ||
|
|
3232e0f082 | ||
|
|
45484d8949 | ||
|
|
e78f38e3c9 | ||
|
|
c94e0048ab | ||
|
|
2316fb1780 | ||
|
|
90750d420f | ||
|
|
11ad5535e3 | ||
|
|
03152e54ef | ||
|
|
8b37443018 | ||
|
|
eb7760ac18 | ||
|
|
ae7815105f |
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 Moshow K ZHENG(Moshow/郑锴/大狼狗)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -27,6 +27,10 @@
|
||||
|
||||
|更新日期|更新内容|
|
||||
|-|-|
|
||||
|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的提交)|
|
||||
|20191128|1.修复支持string-copy导致的以n结尾的字母不显示问题 2.jpa-entity新增swagger@ApiModel@ApiModelProperty注解和SQL字段@Column注解(感谢@yjq907的建议) |
|
||||
|20191126|1.springboot2内置tomcat更换为性能更强大的undertow 2.修复tinyintTransType参数丢失问题 |
|
||||
|20191124|1.java代码结构优化. 2.新增简单的json生成模式 3.新增简单的正则表达式匹配模式(感谢@ydq的贡献) 4.新增对复制String代码中的乱SQL代码的支持 5.优化对JSON的父子节点/处理,JSONObject和JSONArray节点处理,子节点缺失'{'头处理|
|
||||
|
||||
@@ -5,10 +5,8 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@Slf4j
|
||||
public class GeneratorWebApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GeneratorWebApplication.class,args);
|
||||
log.info("项目启动启动成功!访问地址: http://localhost:1234/generator");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.softdev.system.generator.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.web.context.WebServerInitializedEvent;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description 动态获取tomcat启动端口,控制台打印项目访问地址
|
||||
* @Author Gao Hang Hang
|
||||
* @Date 2019-12-27 14:37
|
||||
**/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ServerConfig implements ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private int serverPort;
|
||||
private String serverPath;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(WebServerInitializedEvent event) {
|
||||
this.serverPort = event.getWebServer().getPort();
|
||||
//新增动态path by zhengkai
|
||||
this.serverPath = event.getApplicationContext().getApplicationName();
|
||||
log.info("项目启动启动成功!访问地址: http://localhost:{}{}", serverPort,serverPath);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +1,49 @@
|
||||
package com.softdev.system.generator.config;
|
||||
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 2019-2-11 liutf WebMvcConfig 整合 cors 和 SpringMvc MessageConverter
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
/* @Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedHeaders("x-requested-with")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE")
|
||||
.maxAge(3600);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
//FastJsonHttpMessageConverter
|
||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||
|
||||
List<MediaType> fastMediaTypes = new ArrayList<>();
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
fastConverter.setSupportedMediaTypes(fastMediaTypes);
|
||||
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
fastJsonConfig.setCharset(Charset.forName("UTF-8"));
|
||||
fastConverter.setFastJsonConfig(fastJsonConfig);
|
||||
|
||||
//StringHttpMessageConverter
|
||||
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
|
||||
stringConverter.setDefaultCharset(Charset.forName("UTF-8"));
|
||||
stringConverter.setSupportedMediaTypes(fastMediaTypes);
|
||||
converters.add(stringConverter);
|
||||
converters.add(fastConverter);
|
||||
}
|
||||
package com.softdev.system.generator.config;
|
||||
|
||||
import com.alibaba.fastjson.support.config.FastJsonConfig;
|
||||
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
* 2019-2-11 liutf WebMvcConfig 整合 cors 和 SpringMvc MessageConverter
|
||||
*/
|
||||
@Configuration
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
/* @Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedHeaders("x-requested-with")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS", "TRACE")
|
||||
.maxAge(3600);
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
//FastJsonHttpMessageConverter
|
||||
FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
|
||||
|
||||
List<MediaType> fastMediaTypes = new ArrayList<>();
|
||||
fastMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
|
||||
fastConverter.setSupportedMediaTypes(fastMediaTypes);
|
||||
|
||||
FastJsonConfig fastJsonConfig = new FastJsonConfig();
|
||||
fastJsonConfig.setCharset(StandardCharsets.UTF_8);
|
||||
fastConverter.setFastJsonConfig(fastJsonConfig);
|
||||
|
||||
//StringHttpMessageConverter
|
||||
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
|
||||
stringConverter.setDefaultCharset(StandardCharsets.UTF_8);
|
||||
stringConverter.setSupportedMediaTypes(fastMediaTypes);
|
||||
converters.add(stringConverter);
|
||||
converters.add(fastConverter);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.softdev.system.generator.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.softdev.system.generator.entity.ClassInfo;
|
||||
import com.softdev.system.generator.entity.ParamInfo;
|
||||
import com.softdev.system.generator.entity.ReturnT;
|
||||
@@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -37,7 +39,7 @@ public class IndexController {
|
||||
|
||||
@PostMapping("/genCode")
|
||||
@ResponseBody
|
||||
public ReturnT<Map<String, String>> codeGenerate( ParamInfo paramInfo ) {
|
||||
public ReturnT<Map<String, String>> codeGenerate(@RequestBody ParamInfo paramInfo ) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -59,9 +61,14 @@ public class IndexController {
|
||||
// process the param
|
||||
Map<String, Object> params = new HashMap<String, Object>(8);
|
||||
params.put("classInfo", classInfo);
|
||||
params.put("tableName", classInfo==null?System.currentTimeMillis():classInfo.getTableName());
|
||||
params.put("authorName", paramInfo.getAuthorName());
|
||||
params.put("packageName", paramInfo.getPackageName());
|
||||
params.put("returnUtil", paramInfo.getReturnUtil());
|
||||
params.put("swagger", paramInfo.isSwagger());
|
||||
|
||||
//log the params
|
||||
//log.info(JSON.toJSONString(paramInfo));
|
||||
|
||||
log.info("generator table:"+(classInfo==null?"":classInfo.getTableName())
|
||||
+",field size:"+((classInfo==null||classInfo.getFieldList()==null)?"":classInfo.getFieldList().size()));
|
||||
|
||||
@@ -15,6 +15,7 @@ public class ParamInfo {
|
||||
private String nameCaseType;
|
||||
private String tinyintTransType;
|
||||
private String dataType;
|
||||
private boolean swagger;
|
||||
|
||||
@Data
|
||||
public static class NAME_CASE_TYPE{
|
||||
|
||||
@@ -25,11 +25,13 @@ public class GeneratorServiceImpl implements GeneratorService {
|
||||
public Map<String, String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException {
|
||||
// result
|
||||
Map<String, String> result = new HashMap<String, String>(32);
|
||||
|
||||
result.put("tableName",params.get("tableName")+"");
|
||||
//UI
|
||||
result.put("swagger-ui", freemarkerTool.processString("code-generator/ui/swagger-ui.ftl", params));
|
||||
result.put("element-ui", freemarkerTool.processString("code-generator/ui/element-ui.ftl", params));
|
||||
result.put("bootstrap-ui", freemarkerTool.processString("code-generator/ui/bootstrap-ui.ftl", params));
|
||||
result.put("layui-edit", freemarkerTool.processString("code-generator/ui/layui-edit.ftl", params));
|
||||
result.put("layui-list", freemarkerTool.processString("code-generator/ui/layui-list.ftl", params));
|
||||
//mybatis old
|
||||
result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params));
|
||||
result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params));
|
||||
@@ -47,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>
|
||||
@@ -1 +1 @@
|
||||
{"version": "20191128"}
|
||||
{"version": "20200306"}
|
||||
@@ -7,9 +7,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@@ -4,10 +4,12 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Data
|
||||
* @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;
|
||||
@@ -16,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,26 +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;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@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>
|
||||
|
||||
}
|
||||
@@ -2,9 +2,10 @@
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
public interface I${classInfo.className}DAO {
|
||||
|
||||
int add(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
@@ -6,9 +6,10 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Repository
|
||||
public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao{
|
||||
|
||||
|
||||
@@ -13,13 +13,14 @@ import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="${classInfo.tableName}")
|
||||
@ApiModel("${classInfo.classComment}")
|
||||
@Table(name="${classInfo.tableName}")<#if swagger?exists && swagger==true>
|
||||
@ApiModel("${classInfo.classComment}")</#if>
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -30,9 +31,9 @@ public class ${classInfo.className} implements Serializable {
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/
|
||||
@ApiModelProperty("${fieldItem.fieldComment}")
|
||||
@Column("${fieldItem.columnName}")
|
||||
*/<#if swagger?exists && swagger==true>
|
||||
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
|
||||
@Column(name="${fieldItem.columnName}")
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
|
||||
@@ -15,9 +15,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@@ -14,9 +14,10 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Repository
|
||||
public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> {
|
||||
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
package ${packageName}.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
import ${packageName}.mapper.${classInfo.className}Mapper;
|
||||
import ${packageName}.util.ReturnT;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
@@ -25,14 +34,20 @@ public class ${classInfo.className}Controller {
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id))
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
log.info("${classInfo.className?uncap_first}:"+JSON.toJSONString(${classInfo.className?uncap_first}));
|
||||
${classInfo.className} old${classInfo.className} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",${classInfo.className?uncap_first}.get${classInfo.className}Id()));
|
||||
${classInfo.className?uncap_first}.setModifyDate(new Date());
|
||||
if(old${classInfo.className}!=null){
|
||||
${classInfo.className?uncap_first}Mapper.updateById(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
if(${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_name",${classInfo.className?uncap_first}.get${classInfo.className}Name()))!=null){
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,"保存失败,名字重复");
|
||||
}
|
||||
return ${returnUtil}.success(${classInfo.className?uncap_first});
|
||||
${classInfo.className?uncap_first}.setCreateDate(new Date());
|
||||
${classInfo.className?uncap_first}Mapper.insert(${classInfo.className?uncap_first});
|
||||
}
|
||||
return new ReturnT<>(ReturnT.SUCCESS_CODE,"保存成功");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,11 +55,12 @@ public class ${classInfo.className}Controller {
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id))
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
return ${returnUtil}.success(${classInfo.className?uncap_first});
|
||||
${classInfo.className?uncap_first}Mapper.deleteById(id);
|
||||
return new ReturnT<>(ReturnT.SUCCESS_CODE,"删除成功");
|
||||
}else{
|
||||
return ${returnUtil}.error("没有找到该对象");
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,"没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,11 +69,11 @@ public class ${classInfo.className}Controller {
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("id",id))
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
return ${returnUtil}.success(${classInfo.className?uncap_first});
|
||||
return new ReturnT<>(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
return ${returnUtil}.error("没有找到该对象");
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE,"没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,17 +81,33 @@ public class ${classInfo.className}Controller {
|
||||
* 分页查询
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
public Object list(${classInfo.className} ${classInfo.className?uncap_first},
|
||||
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||
public Object list(String searchParams,
|
||||
@RequestParam(required = false, defaultValue = "0") int page,
|
||||
@RequestParam(required = false, defaultValue = "10") int limit) {
|
||||
log.info("page:"+page+"-limit:"+limit+"-json:"+ JSON.toJSONString(searchParams));
|
||||
//分页构造器
|
||||
Page<${classInfo.className}> page = new Page<${classInfo.className}>(pageNumber,pageSize);
|
||||
Page<${classInfo.className}> buildPage = new Page<${classInfo.className}>(page,limit);
|
||||
//条件构造器
|
||||
QueryWrapper<${classInfo.className}> queryWrapperw = new QueryWrapper<${classInfo.className}>(${classInfo.className?uncap_first});
|
||||
QueryWrapper<${classInfo.className}> queryWrapper = new QueryWrapper<${classInfo.className}>();
|
||||
if(StringUtils.isNotEmpty(searchParams)&&JSON.isValid(searchParams)) {
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = JSON.parseObject(searchParams, ${classInfo.className}.class);
|
||||
queryWrapper.eq(StringUtils.isNoneEmpty(${classInfo.className?uncap_first}.get${classInfo.className}Name()), "${classInfo.className?uncap_first}_name", ${classInfo.className?uncap_first}.get${classInfo.className}Name());
|
||||
}
|
||||
//执行分页
|
||||
IPage<${classInfo.className}> pageList = certPersonMapper.selectPage(page, queryWrapperw);
|
||||
IPage<${classInfo.className}> pageList = ${classInfo.className?uncap_first}Mapper.selectPage(buildPage, queryWrapper);
|
||||
//返回结果
|
||||
return ${returnUtil}.success(pageList);
|
||||
return new ReturnT<>(pageList.getRecords(),Integer.parseInt(pageList.getTotal()+""));
|
||||
}
|
||||
@GetMapping("/list")
|
||||
public ModelAndView listPage(){
|
||||
return new ModelAndView("cms/${classInfo.className?uncap_first}-list");
|
||||
}
|
||||
@GetMapping("/edit")
|
||||
public ModelAndView editPage(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = ${classInfo.className?uncap_first}Mapper.selectOne(new QueryWrapper<${classInfo.className}>().eq("${classInfo.className?uncap_first}_id",id));
|
||||
return new ModelAndView("cms/${classInfo.className?uncap_first}-edit","${classInfo.className?uncap_first}",${classInfo.className?uncap_first});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
}
|
||||
@@ -1,14 +1,37 @@
|
||||
package ${packageName}.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import ${packageName}.entity.${classInfo.className};
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@Repository
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@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);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value = "/${classInfo.className}")
|
||||
public class ${classInfo.className}Controller {
|
||||
@@ -21,7 +21,7 @@ public class ${classInfo.className}Controller {
|
||||
private ${classInfo.className}Service ${classInfo.className?uncap_first}Service;
|
||||
|
||||
/**
|
||||
* [新增]
|
||||
* 新增
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@@ -31,7 +31,7 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* [刪除]
|
||||
* 刪除
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@@ -41,7 +41,7 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* [更新]
|
||||
* 更新
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@@ -51,7 +51,7 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* [查询] 根据主键 id 查询
|
||||
* 查询 根据主键 id 查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
@@ -61,7 +61,7 @@ public class ${classInfo.className}Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* [查询] 分页查询
|
||||
* 查询 分页查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
|
||||
@@ -4,51 +4,51 @@ import org.springframework.stereotype.Repository;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Mapper
|
||||
@Repository
|
||||
public interface ${classInfo.className}Mapper {
|
||||
|
||||
/**
|
||||
* [新增]
|
||||
* 新增
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int insert(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* [刪除]
|
||||
* 刪除
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int delete(int id);
|
||||
|
||||
/**
|
||||
* [更新]
|
||||
* 更新
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
int update(${classInfo.className} ${classInfo.className?uncap_first});
|
||||
|
||||
/**
|
||||
* [查询] 根据主键 id 查询
|
||||
* 查询 根据主键 id 查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
${classInfo.className} load(int id);
|
||||
|
||||
/**
|
||||
* [查询] 分页查询
|
||||
* 查询 分页查询
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
List<${classInfo.className}> pageList(int offset,int pagesize);
|
||||
|
||||
/**
|
||||
* [查询] 分页查询 count
|
||||
* 查询 分页查询 count
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
**/
|
||||
|
||||
@@ -3,9 +3,10 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
public interface ${classInfo.className}Service {
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy/MM/dd')}
|
||||
*/
|
||||
* @description ${classInfo.classComment}
|
||||
* @author ${authorName}
|
||||
* @date ${.now?string('yyyy-MM-dd HH:mm:ss')}
|
||||
*/
|
||||
@Service
|
||||
public class ${classInfo.className}ServiceImpl implements ${classInfo.className}Service {
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>layuimini</title>
|
||||
<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">
|
||||
<style>
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="layui-form layuimini-form">
|
||||
<input type="hidden" name="${classInfo.className?uncap_first}Id" value="" class="layui-input">
|
||||
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label required">${fieldItem.fieldComment}</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="${fieldItem.fieldName}" lay-verify="required" lay-reqtext="${fieldItem.fieldComment}不能为空" placeholder="请输入${fieldItem.fieldComment}" value="" class="layui-input">
|
||||
<#--<tip>${fieldItem.fieldComment}</tip>-->
|
||||
</div>
|
||||
</div>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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,
|
||||
layer = layui.layer,
|
||||
$ = layui.$;
|
||||
|
||||
//监听提交
|
||||
form.on('submit(saveBtn)', function (data) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: "¥{request.contextPath}/${classInfo.className?uncap_first}/save",
|
||||
data:JSON.stringify(data.field),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
success: function (responseData) {
|
||||
if (responseData.code === 200) {
|
||||
layer.msg(responseData.msg, function () {
|
||||
// 关闭弹出层
|
||||
//layer.close(index);
|
||||
var iframeIndex = parent.layer.getFrameIndex(window.name);
|
||||
parent.layer.close(iframeIndex);
|
||||
parent.searchBtn.click();
|
||||
});
|
||||
} else {
|
||||
layer.msg(responseData.msg, function () {
|
||||
//window.location = '/index.html';
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,189 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>layuimini</title>
|
||||
<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">
|
||||
</head>
|
||||
<body>
|
||||
<div class="layuimini-container">
|
||||
<div class="layuimini-main">
|
||||
|
||||
<fieldset class="table-search-fieldset">
|
||||
<legend>搜索信息</legend>
|
||||
<div style="margin: 10px 10px 10px 10px">
|
||||
<form class="layui-form layui-form-pane" action="">
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-inline">
|
||||
<label class="layui-form-label">${classInfo.classComment}Id</label>
|
||||
<div class="layui-input-inline">
|
||||
<input type="text" name="${classInfo.className?uncap_first}Id" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<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>
|
||||
</div>
|
||||
<div class="layui-inline">
|
||||
<button id="searchBtn" type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<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>-->
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
|
||||
|
||||
<script type="text/html" id="currentTableBar">
|
||||
<a class="layui-btn layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
|
||||
<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
|
||||
</script>
|
||||
|
||||
<script type="text/html" id="statusTemplate">
|
||||
{{# if(d.status = 1){ }}
|
||||
启用
|
||||
{{# } else { }}
|
||||
停用
|
||||
{{# } }}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<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,
|
||||
form = layui.form,
|
||||
table = layui.table,
|
||||
layuimini = layui.layuimini;
|
||||
|
||||
table.render({
|
||||
elem: '#currentTableId',
|
||||
method: 'post',
|
||||
url: '¥{request.contextPath}/${classInfo.className?uncap_first}/list',
|
||||
toolbar: '#toolbarDemo',
|
||||
defaultToolbar: ['filter', 'exports', 'print', {
|
||||
title: '提示',
|
||||
layEvent: 'LAYTABLE_TIPS',
|
||||
icon: 'layui-icon-tips'
|
||||
}],
|
||||
cols: [[
|
||||
{type: "checkbox", width: 50, fixed: "left"},
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
{field: '${fieldItem.fieldName}', width: 150, title: '${fieldItem.fieldComment}', sort: true}, <#if fieldItem_has_next> </#if>
|
||||
</#list>
|
||||
</#if>
|
||||
{title: '操作', minWidth: 50, templet: '#currentTableBar', fixed: "right", align: "center"}
|
||||
]],
|
||||
limits: [10, 20, 50 , 100],
|
||||
limit: 10,
|
||||
page: true
|
||||
});
|
||||
|
||||
var result;
|
||||
// 监听搜索操作
|
||||
form.on('submit(data-search-btn)', function (data) {
|
||||
result = JSON.stringify(data.field);
|
||||
// layer.alert(result, {
|
||||
// title: '最终的搜索信息'
|
||||
// });
|
||||
|
||||
//执行搜索重载
|
||||
table.reload('currentTableId', {
|
||||
page: {
|
||||
curr: 1
|
||||
}
|
||||
, where: {
|
||||
searchParams: result
|
||||
}
|
||||
}, 'data');
|
||||
|
||||
return false;
|
||||
});
|
||||
var searchBtn = $("#searchBtn");
|
||||
// 监听添加操作
|
||||
$(".data-add-btn").on("click", function () {
|
||||
var index = layer.open({
|
||||
title: '添加${classInfo.classComment}',
|
||||
type: 2,
|
||||
shade: 0.2,
|
||||
maxmin:true,
|
||||
shadeClose: true,
|
||||
area: ['800px', '500px'],
|
||||
content: '¥{request.contextPath}/${classInfo.className?uncap_first}/edit?id=0',
|
||||
});
|
||||
layer.full(index);
|
||||
return false;
|
||||
});
|
||||
|
||||
// 监听删除操作
|
||||
$(".data-delete-btn").on("click", function () {
|
||||
var checkStatus = table.checkStatus('currentTableId')
|
||||
, data = checkStatus.data;
|
||||
layer.alert(JSON.stringify(data));
|
||||
});
|
||||
|
||||
//监听表格复选框选择
|
||||
table.on('checkbox(currentTableFilter)', function (obj) {
|
||||
console.log(obj)
|
||||
});
|
||||
|
||||
//监听表格编辑删除等功能按钮
|
||||
table.on('tool(currentTableFilter)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'edit') {
|
||||
var index = layer.open({
|
||||
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,
|
||||
});
|
||||
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",
|
||||
data:{"id":obj.data.${classInfo.className?uncap_first}Id},
|
||||
success: function (responseData) {
|
||||
if (responseData.code === 200) {
|
||||
layer.msg(responseData.msg, function () {
|
||||
obj.del();
|
||||
});
|
||||
} else {
|
||||
layer.msg(responseData.msg, function () {
|
||||
//window.location = '/index.html';
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
layer.close(index);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -42,37 +42,103 @@
|
||||
genCodeArea.setSize('auto','auto');
|
||||
|
||||
var codeData;
|
||||
|
||||
// 使用:var jsonObj = $("#formId").serializeObject();
|
||||
$.fn.serializeObject = function()
|
||||
{
|
||||
var o = {};
|
||||
var a = this.serializeArray();
|
||||
$.each(a, function() {
|
||||
if (o[this.name]) {
|
||||
if (!o[this.name].push) {
|
||||
o[this.name] = [o[this.name]];
|
||||
}
|
||||
o[this.name].push(this.value || '');
|
||||
} else {
|
||||
o[this.name] = this.value || '';
|
||||
}
|
||||
});
|
||||
return o;
|
||||
};
|
||||
var historyCount=0;
|
||||
//初始化清除session
|
||||
if (window.sessionStorage){
|
||||
//修复当F5刷新的时候,session没有清空各个值,但是页面的button没了。
|
||||
sessionStorage.clear();
|
||||
}
|
||||
/**
|
||||
* 生成代码
|
||||
*/
|
||||
$('#btnGenCode').click(function () {
|
||||
var tableSql = ddlSqlArea.getValue();
|
||||
var jsonData = {
|
||||
"tableSql": ddlSqlArea.getValue(),
|
||||
"packageName":$("#packageName").val(),
|
||||
"returnUtil":$("#returnUtil").val(),
|
||||
"authorName":$("#authorName").val(),
|
||||
"dataType":$("#dataType").val(),
|
||||
"tinyintTransType":$("#tinyintTransType").val(),
|
||||
"nameCaseType":$("#nameCaseType").val(),
|
||||
"swagger":$("#isSwagger").val()
|
||||
};
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: base_url + "/genCode",
|
||||
data: {
|
||||
"tableSql": tableSql,
|
||||
"packageName":$("#packageName").val(),
|
||||
"returnUtil":$("#returnUtil").val(),
|
||||
"authorName":$("#authorName").val(),
|
||||
"dataType":$("#dataType").val(),
|
||||
"tinyintTransType":$("#tinyintTransType").val(),
|
||||
"nameCaseType":$("#nameCaseType").val()
|
||||
},
|
||||
data:(JSON.stringify(jsonData)),
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
success: function (data) {
|
||||
if (data.code == 200) {
|
||||
if (data.code === 200) {
|
||||
codeData = data.data;
|
||||
genCodeArea.setValue(codeData.beetlentity);
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
$.toast("√ 代码生成成功");
|
||||
//添加历史记录
|
||||
addHistory(codeData);
|
||||
} else {
|
||||
$.toast("× 代码生成失败 :"+data.msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
/**
|
||||
* 切换历史记录
|
||||
*/
|
||||
function getHistory(tableName){
|
||||
if (window.sessionStorage){
|
||||
var valueSession = sessionStorage.getItem(tableName);
|
||||
codeData = JSON.parse(valueSession);
|
||||
$.toast("$ 切换历史记录成功:"+tableName);
|
||||
genCodeArea.setValue(codeData.entity);
|
||||
}else{
|
||||
console.log("浏览器不支持sessionStorage");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 添加历史记录
|
||||
*/
|
||||
function addHistory(data){
|
||||
if (window.sessionStorage){
|
||||
//console.log(historyCount);
|
||||
if(historyCount>=9){
|
||||
$("#history").find(".btn:last").remove();
|
||||
historyCount--;
|
||||
}
|
||||
var tableName=data.tableName;
|
||||
var valueSession = sessionStorage.getItem(tableName);
|
||||
if(valueSession!==undefined && valueSession!=null){
|
||||
sessionStorage.removeItem(tableName);
|
||||
}else{
|
||||
$("#history").prepend('<button id="his-'+tableName+'" type="button" class="btn">'+tableName+'</button>');
|
||||
//$("#history").prepend('<button id="his-'+tableName+'" onclick="getHistory(\''+tableName+'\');" type="button" class="btn">'+tableName+'</button>');
|
||||
$("#his-"+tableName).bind('click', function () {getHistory(tableName)});
|
||||
}
|
||||
sessionStorage.setItem(tableName,JSON.stringify(data));
|
||||
historyCount++;
|
||||
}else{
|
||||
console.log("浏览器不支持sessionStorage");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按钮事件组
|
||||
*/
|
||||
@@ -151,7 +217,7 @@
|
||||
<div class="container">
|
||||
<h2>Spring Boot Code Generator!</h2>
|
||||
<p class="lead">
|
||||
√基于SpringBoot2+Freemarker的代码生成器,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
|
||||
√基于SpringBoot2+Freemarker的<a class="lead" href="https://github.com/moshowgame/SpringBootCodeGenerator">代码生成器</a>,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
|
||||
√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码。<br>
|
||||
如果发现有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>
|
||||
</p>
|
||||
@@ -165,7 +231,7 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">返回封装</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" id="returnUtil" name="returnUtil" value="ApiReturnObject">
|
||||
<input type="text" class="form-control" id="returnUtil" name="returnUtil" value="new ReturnT<>">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">包名路径</span>
|
||||
</div>
|
||||
@@ -201,6 +267,14 @@
|
||||
<option value="UnderScoreCase">下划线</option>
|
||||
<#--<option value="UpperUnderScoreCase">大写下划线</option>-->
|
||||
</select>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">swagger-ui</span>
|
||||
</div>
|
||||
<select type="text" class="form-control" id="isSwagger"
|
||||
name="isSwagger">
|
||||
<option value="false">关闭</option>
|
||||
<option value="true">开启</option>
|
||||
</select>
|
||||
</div>
|
||||
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
|
||||
CREATE TABLE 'userinfo' (
|
||||
@@ -211,6 +285,7 @@ CREATE TABLE 'userinfo' (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户信息'
|
||||
</textarea><br>
|
||||
<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>
|
||||
<div id="history" class="btn-group" role="group" aria-label="Basic example"></div>
|
||||
<hr>
|
||||
<!-- Example row of columns -->
|
||||
<div class="row" style="margin-top: 10px;">
|
||||
@@ -249,12 +324,13 @@ 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>
|
||||
</div>
|
||||
|
||||
<div class="btn-toolbar col-md-5" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="btn-toolbar col-md-7" 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">UI</div>
|
||||
@@ -264,6 +340,8 @@ CREATE TABLE 'userinfo' (
|
||||
<button type="button" class="btn btn-default generator" id="swagger-ui">swagger-ui</button>
|
||||
<button type="button" class="btn btn-default generator" id="element-ui">element-ui</button>
|
||||
<button type="button" class="btn btn-default generator" id="bootstrap-ui">bootstrap-ui</button>
|
||||
<button type="button" class="btn btn-default generator" id="layui-edit">layui-edit</button>
|
||||
<button type="button" class="btn btn-default generator" id="layui-list">layui-list</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -320,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 -->
|
||||
|
||||
Reference in New Issue
Block a user