mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
commit
72257e00bd
122
README.md
122
README.md
@ -1,65 +1,75 @@
|
||||
# SpringBootCodeGenerator
|
||||

|
||||

|
||||

|
||||
[](https://travis-ci.org/moshowgame/SpringBootCodeGenerator)
|
||||
<br>
|
||||
|
||||
SpringBootCodeGenerator
|
||||
----
|
||||
√基于SpringBoot2+Freemarker的代码生成器,√以释放双手为目的,√支持mysql/oracle/pgsql三大数据库,<br>
|
||||
√用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码.<br><br>
|
||||
另外,感谢bejson三叔将他部署在 http://java.bejson.com/generator 上,目前是besjon专供工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢).
|
||||
<br><br>
|
||||
<table><tbody>
|
||||
<tr><td>访问路径</td> <td>http://127.0.0.1:1234/generator</td></tr>
|
||||
<tr><td>在线地址</td> <td>http://java.bejson.com/generator</td></tr>
|
||||
<tr><td>CSDN博客</td> <td>http://zhengkai.blog.csdn.net</td></tr>
|
||||
<tr><td></td> <td></td></tr>
|
||||
<tr><td>更新日期</td> <td>更新内容</td></tr>
|
||||
<tr><td>20191123<td>1.移除频繁出错和被过滤的layer,改为jquery-toast. 2.Util功能优化,新增json和xml.</td></tr>
|
||||
<tr><td>20191116<td>优化对primary关键字的处理(感谢@liujiansgit的反馈). </td></tr>
|
||||
<tr><td>20191115<td>1.添加tinyint类型转换(感谢@lixiliang&@liujiansgit的Suggestion) 2.添加一键复制功能(感谢@gaohanghang的Suggestion) 3.Mybatis的insert增加keyProperty="id"用于返回自增id(感谢@88888888888888888888的Suggestion) 4.优化date类型的支持(感谢@SteveLsf的反馈) 5.其他一些优化. </td></tr>
|
||||
<tr><td>20191015<td>修复jdbcTemplates中insert语句第一个字段丢失的问题. </td></tr>
|
||||
<tr><td>20190915<td>1.添加对象getset模板 2.添加sql模板 3.启动类添加日志输出,方便项目使用(感谢@gaohanghang 的pull request) </td></tr>
|
||||
<tr><td>20190910-2<td>优化以及更新Maven依赖,减少打包体积. </td></tr>
|
||||
<tr><td>20190910-1<td>1.修复mapper接口load方法,但是xml中方法不匹配问题 2.移除mapper中CRUD时的@param 注解,会影响xml的解析(感谢@caojiantao的反馈).3.优化MyBatis的xml文件对Oracle的支持.(感谢@wylove1992的反馈) 4.新增对boolean的处理(感谢@violinxsc的反馈)以及优化tinyint类型生成boolean类型问题(感谢@hahaYhui的反馈) </td></tr>
|
||||
<tr><td>20190909<td>添加是否下划线转换为驼峰的选择(感谢@youngking28 的pull request).</td></tr>
|
||||
<tr><td>20190518<td>1.优化注释 2.修改 mybatis模板中 controller注解 3.修改 mybatis模板中 dao文件使用为 mapper文件 4.修改 mybatis模板中 service实现类中的一个 bug 5.修改 index.ftl文件中 mybatis模板的 dao -> mapper(感谢@unqin的pull request)</td></tr>
|
||||
<tr><td>20190511<td>优化mybatis模块的dao和xml模板,修改dao接口注解为@Repository,所有dao参数改为包装类,删除update语句最后的UpdateTime = NOW(),修改dao接口文件的方法注释使其更符合javaDoc的标准,修改insert语句增加插入行主键的返回,修改load的方法名为selectByPrimaryKey,修改xml的update语句新增动态if判空,修改xml的insert语句新增动态插入判空,更符合mybatisGenerator标准(感谢@Archer-Wen的贡献 ).</td></tr>
|
||||
<tr><td>20190429<td>新增返回封装工具类设置,优化对oracle注释comment on column的支持(感谢@liukex反馈),优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 ).</td></tr>
|
||||
<tr><td>20190211<td>提交gitignore,解决StringUtils.lowerCaseFirst潜在的NPE异常,校验修改为@RequestParam参数校验,lombok之@Data和@Slf4j优化,fix JdbcDAO模板类名显示为中文问题,WebMvcConfig整合MessageConverter,模板代码分类(感谢@liutf和@tfgzs的pull request).</td></tr>
|
||||
<tr><td>20190210<td>实体生成规则切换为包装类型,不再采用基本数据类型,为实体类生成添加显示的默认构造方法(感谢@h2so的pull request).</td></tr>
|
||||
<tr><td>20190106<td>修复处理number/decimal(x,x)类型的逻辑(感谢@arthaschan的反馈),修复JdbcTemplates模板两处错误(感谢@everflourish的反馈).</td></tr>
|
||||
<tr><td>20181212<td>首页UI优化,新增MybatisPlus模块(感谢@三叔同事的建议),修复作者名和包名获取失败问题(感谢@Yanch1994的反馈).</td></tr>
|
||||
<tr><td>20181122<td>优化正则表达式点号的处理,优化处理字段类型,对number类型增加int,long,BigDecimal的区分判断(感谢@lshz0088的指导).</td></tr>
|
||||
<tr><td>20181108<td>修复非字段描述"KEY FK_xxxx (xxxx)"导致生成KEY字段情况(感谢@tornadoorz反馈).</td></tr>
|
||||
<tr><td>20181018<td>支持double(x,x)的类型,以及comment里面包含一些特殊字符的处理(感谢@tanwubo的反馈).</td></tr>
|
||||
<tr><td>20181010<td>CDN变更,修复CDN不稳定导致网页js报错问题.</td></tr>
|
||||
<tr><td>20181003<td>新增element-ui/bootstrap生成.</td></tr>
|
||||
<tr><td>20181002<td>修复公共CDN之Layer.js404问题,导致项目无法生成.</td></tr>
|
||||
<tr><td>20180927<td>优化COMMENT提取逻辑,支持多种复杂情况的注释(感谢@raodeming的反馈).</td></tr>
|
||||
<tr><td>20180926<td>全新BeetlSQL模块,以及一些小细节优化(感谢@三叔同事的建议).</td></tr>
|
||||
<tr><td>20180925<td>优化SQL表和字段备注的推断,包括pgsql/oralce的comment on column/table情况处理等.</td></tr>
|
||||
<tr><td>20180918<td>优化SQL类型推断.优化PrimaryKey判断.修复jpacontroller中Repository拼写错误问题.</td></tr>
|
||||
<tr><td>20180917<td>全新首页,静态文件全部采用CDN.新增jdbcTemplate模块.</td></tr>
|
||||
<tr><td>20180916-2<td>优化oracle支持,优化DDL语句中"或者'或者空格的支持.</td></tr>
|
||||
<tr><td>20180916-1<td>补充char/clob/blob/json等类型,如果类型未知,默认为String.</td></tr>
|
||||
<tr><td>20180915<td>新增Swagger-UI模板.修复一些命名和导入问题.JPA的Entity默认第一个字段为Id,如果不是请手工修改.</td></tr>
|
||||
<tr><td>20180913<td>修复字段没有描述以及类型为DATE型导致的问题.新增JPA的Controller模板.</td></tr>
|
||||
<tr><td>20180831<td>初始化项目.新增JPA系列Entity+Repository模板.</td></tr>
|
||||
</tbody></table>
|
||||
|
||||
<table><tbody>
|
||||
<tr><td>字段名</td> <td>说明</td></tr>
|
||||
<tr><td>packageName</td> <td>自定义的包名</td></tr>
|
||||
<tr><td>authorName</td> <td>自定义的作者名</td></tr>
|
||||
<tr><td>returnUtil</td> <td>自定义的返回Util</td></tr>
|
||||
<tr><td>tableName</td> <td>sql中的表名</td></tr>
|
||||
<tr><td>className</td> <td>java类名</td></tr>
|
||||
<tr><td>classComment</td> <td>sql表备注/java类备注</td></tr>
|
||||
<tr><td>fieldName</td> <td>字段名</td></tr>
|
||||
<tr><td>fieldComment</td> <td>字段备注</td></tr>
|
||||
</tbody></table>
|
||||
# Description
|
||||
- √ 基于SpringBoot2+Freemarker+Bootstrap
|
||||
- √ 以释放双手为目的
|
||||
- √ 支持mysql/oracle/pgsql三大数据库
|
||||
- √ 用DDL-SQL语句生成JPA/JdbcTemplate/Mybatis/MybatisPlus/BeetlSQL相关代码.
|
||||
|
||||
|
||||
# Url
|
||||
|
||||
|访问路径|http://localhost:1234/generator|
|
||||
|-|-|
|
||||
|在线地址|http://java.bejson.com/generator|
|
||||
|CSDN博客|http://zhengkai.blog.csdn.net|
|
||||
|
||||
感谢bejson三叔将他部署在[BEJSON](www.bejson.com)上,目前是besjon专供工具(线上版本不一定是最新的,会有延迟,请谅解,谢谢).
|
||||
|
||||
|
||||
# Update
|
||||
|
||||
|更新日期|更新内容|
|
||||
|-|-|
|
||||
|20191124|1.java代码结构优化. 2.新增简单的json生成模式 3.新增简单的正则表达式匹配模式(感谢@ydq的贡献) 4.新增对复制String代码中的乱SQL代码的支持 5.优化对JSON的父子节点/处理,JSONObject和JSONArray节点处理,子节点缺失'{'头处理|
|
||||
|20191123|1.移除频繁出错和被过滤的layer,改为jquery-toast. 2.Util功能优化,新增json和xml.|
|
||||
|20191116|优化对primary关键字的处理(感谢@liujiansgit的反馈). |
|
||||
|20191115|1.添加tinyint类型转换(感谢@lixiliang&@liujiansgit的Suggestion) 2.添加一键复制功能(感谢@gaohanghang的Suggestion) 3.Mybatis的insert增加keyProperty="id"用于返回自增id(感谢@88888888888888888888的Suggestion) 4.优化date类型的支持(感谢@SteveLsf的反馈) 5.其他一些优化. |
|
||||
|20191015|修复jdbcTemplates中insert语句第一个字段丢失的问题. |
|
||||
|20190915|1.添加对象getset模板 2.添加sql模板 3.启动类添加日志输出,方便项目使用(感谢@gaohanghang 的pull request) |
|
||||
|20190910-2|优化以及更新Maven依赖,减少打包体积. |
|
||||
|20190910-1|1.修复mapper接口load方法,但是xml中方法不匹配问题 2.移除mapper中CRUD时的@param 注解,会影响xml的解析(感谢@caojiantao的反馈).3.优化MyBatis的xml文件对Oracle的支持.(感谢@wylove1992的反馈) 4.新增对boolean的处理(感谢@violinxsc的反馈)以及优化tinyint类型生成boolean类型问题(感谢@hahaYhui的反馈) |
|
||||
|20190909|添加是否下划线转换为驼峰的选择(感谢@youngking28 的pull request).|
|
||||
|20190518|1.优化注释 2.修改 mybatis模板中 controller注解 3.修改 mybatis模板中 dao文件使用为 mapper文件 4.修改 mybatis模板中 service实现类中的一个 bug 5.修改 index.ftl文件中 mybatis模板的 dao -> mapper(感谢@unqin的pull request)|
|
||||
|20190511|优化mybatis模块的dao和xml模板,修改dao接口注解为@Repository,所有dao参数改为包装类,删除update语句最后的UpdateTime = NOW(),修改dao接口文件的方法注释使其更符合javaDoc的标准,修改insert语句增加插入行主键的返回,修改load的方法名为selectByPrimaryKey,修改xml的update语句新增动态if判空,修改xml的insert语句新增动态插入判空,更符合mybatisGenerator标准(感谢@Archer-Wen的贡献 ).|
|
||||
|20190429|新增返回封装工具类设置,优化对oracle注释comment on column的支持(感谢@liukex反馈),优化对普通和特殊storage关键字的判断(感谢@AhHeadFloating的反馈 ).|
|
||||
|20190211|提交gitignore,解决StringUtils.lowerCaseFirst潜在的NPE异常,校验修改为@RequestParam参数校验,lombok之@Data和@Slf4j优化,fix JdbcDAO模板类名显示为中文问题,WebMvcConfig整合MessageConverter,模板代码分类(感谢@liutf和@tfgzs的pull request).|
|
||||
|20190210|实体生成规则切换为包装类型,不再采用基本数据类型,为实体类生成添加显示的默认构造方法(感谢@h2so的pull request).|
|
||||
|20190106|修复处理number/decimal(x,x)类型的逻辑(感谢@arthaschan的反馈),修复JdbcTemplates模板两处错误(感谢@everflourish的反馈).|
|
||||
|20181212|首页UI优化,新增MybatisPlus模块(感谢@三叔同事的建议),修复作者名和包名获取失败问题(感谢@Yanch1994的反馈).|
|
||||
|20181122|优化正则表达式点号的处理,优化处理字段类型,对number类型增加int,long,BigDecimal的区分判断(感谢@lshz0088的指导).|
|
||||
|20181108|修复非字段描述"KEY FK_xxxx (xxxx)"导致生成KEY字段情况(感谢@tornadoorz反馈).|
|
||||
|20181018|支持double(x,x)的类型,以及comment里面包含一些特殊字符的处理(感谢@tanwubo的反馈).|
|
||||
|20181010|CDN变更,修复CDN不稳定导致网页js报错问题.|
|
||||
|20181003|新增element-ui/bootstrap生成.|
|
||||
|20181002|修复公共CDN之Layer.js404问题,导致项目无法生成.|
|
||||
|20180927|优化COMMENT提取逻辑,支持多种复杂情况的注释(感谢@raodeming的反馈).|
|
||||
|20180926|全新BeetlSQL模块,以及一些小细节优化(感谢@三叔同事的建议).|
|
||||
|20180925|优化SQL表和字段备注的推断,包括pgsql/oralce的comment on column/table情况处理等.|
|
||||
|20180918|优化SQL类型推断.优化PrimaryKey判断.修复jpacontroller中Repository拼写错误问题.|
|
||||
|20180917|全新首页,静态文件全部采用CDN.新增jdbcTemplate模块.|
|
||||
|20180916|1.优化oracle支持,优化DDL语句中"或者'或者空格的支持. 2.补充char/clob/blob/json等类型,如果类型未知,默认为String.|
|
||||
|20180915|新增Swagger-UI模板.修复一些命名和导入问题.JPA的Entity默认第一个字段为Id,如果不是请手工修改.|
|
||||
|20180913|修复字段没有描述以及类型为DATE型导致的问题.新增JPA的Controller模板.|
|
||||
|20180831|初始化项目.新增JPA系列Entity+Repository模板.|
|
||||
|
||||
# FieldName
|
||||
|字段名|说明|
|
||||
|-|-|
|
||||
|packageName|自定义的包名|
|
||||
|authorName|自定义的作者名|
|
||||
|returnUtil|自定义的返回Util|
|
||||
|tableName|sql中的表名|
|
||||
|className|java类名|
|
||||
|classComment|sql表备注/java类备注|
|
||||
|fieldName|字段名|
|
||||
|fieldComment|字段备注|
|
||||
|
||||
|
||||
<img src="./codegenerator1.png">
|
||||
<img src="./codegenerator2.png">
|
||||
|
||||
@ -2,22 +2,19 @@ package com.softdev.system.generator.config;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.softdev.system.generator.entity.ReturnT;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.softdev.system.generator.util.ApiReturnObject;
|
||||
import com.softdev.system.generator.util.ApiReturnUtil;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalDefaultExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
@ResponseBody
|
||||
public ApiReturnObject defaultExceptionHandler(HttpServletRequest req,Exception e) {
|
||||
public ReturnT defaultExceptionHandler(HttpServletRequest req,Exception e) {
|
||||
e.printStackTrace();
|
||||
//return new ApiReturnObject("01","server error", e.getMessage());
|
||||
return ApiReturnUtil.error("服务器异常",e.getMessage());
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package com.softdev.system.generator.controller;
|
||||
|
||||
import com.softdev.system.generator.entity.ClassInfo;
|
||||
import com.softdev.system.generator.entity.ParamInfo;
|
||||
import com.softdev.system.generator.entity.ReturnT;
|
||||
import com.softdev.system.generator.service.GeneratorService;
|
||||
import com.softdev.system.generator.util.CodeGenerateException;
|
||||
import com.softdev.system.generator.util.FreemarkerTool;
|
||||
import com.softdev.system.generator.util.TableParseUtil;
|
||||
import freemarker.template.TemplateException;
|
||||
@ -9,9 +12,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
@ -26,94 +27,51 @@ import java.util.Map;
|
||||
public class IndexController {
|
||||
|
||||
@Autowired
|
||||
private FreemarkerTool freemarkerTool;
|
||||
private GeneratorService generatorService;
|
||||
|
||||
@RequestMapping("/")
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping("/genCode")
|
||||
@PostMapping("/genCode")
|
||||
@ResponseBody
|
||||
public ReturnT<Map<String, String>> codeGenerate(String tableSql,
|
||||
//2019-2-10 liutf 修改为@RequestParam参数校验
|
||||
@RequestParam(required = false, defaultValue = "大狼狗") String authorName,
|
||||
@RequestParam(required = false, defaultValue = "com.softdev.system")String packageName,
|
||||
@RequestParam(required = false, defaultValue = "ApiReturnUtil")String returnUtil,
|
||||
@RequestParam(required = false, defaultValue = "true")boolean isUnderLineToCamelCase,
|
||||
@RequestParam(required = false, defaultValue = "boolean")String tinyintTransType
|
||||
) {
|
||||
|
||||
public ReturnT<Map<String, String>> codeGenerate( ParamInfo paramInfo ) {
|
||||
|
||||
try {
|
||||
|
||||
if (StringUtils.isBlank(tableSql)) {
|
||||
if (StringUtils.isBlank(paramInfo.getTableSql())) {
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, "表结构信息不可为空");
|
||||
}
|
||||
|
||||
// parse table
|
||||
ClassInfo classInfo = TableParseUtil.processTableIntoClassInfo(tableSql, isUnderLineToCamelCase, tinyintTransType);
|
||||
ClassInfo classInfo = null;
|
||||
switch (paramInfo.getDataType()){
|
||||
//parse json
|
||||
case "json":classInfo = TableParseUtil.processJsonToClassInfo(paramInfo);break;
|
||||
//parse sql by regex
|
||||
case "sql-regex":classInfo = TableParseUtil.processTableToClassInfoByRegex(paramInfo);break;
|
||||
//default parse sql by java
|
||||
default : classInfo = TableParseUtil.processTableIntoClassInfo(paramInfo);break;
|
||||
}
|
||||
|
||||
// code genarete
|
||||
// process the param
|
||||
Map<String, Object> params = new HashMap<String, Object>(8);
|
||||
params.put("classInfo", classInfo);
|
||||
params.put("authorName", authorName);
|
||||
params.put("packageName", packageName);
|
||||
params.put("returnUtil", returnUtil);
|
||||
params.put("authorName", paramInfo.getAuthorName());
|
||||
params.put("packageName", paramInfo.getPackageName());
|
||||
params.put("returnUtil", paramInfo.getReturnUtil());
|
||||
|
||||
// result
|
||||
Map<String, String> result = new HashMap<String, String>(32);
|
||||
// generate the code 需要加新的模板请在里面改
|
||||
Map<String, String> result = generatorService.getResultByParams(params);
|
||||
|
||||
//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));
|
||||
//mybatis old
|
||||
result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params));
|
||||
result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params));
|
||||
result.put("service_impl", freemarkerTool.processString("code-generator/mybatis/service_impl.ftl", params));
|
||||
result.put("mapper", freemarkerTool.processString("code-generator/mybatis/mapper.ftl", params));
|
||||
result.put("mybatis", freemarkerTool.processString("code-generator/mybatis/mybatis.ftl", params));
|
||||
result.put("model", freemarkerTool.processString("code-generator/mybatis/model.ftl", params));
|
||||
//jpa
|
||||
result.put("entity", freemarkerTool.processString("code-generator/jpa/entity.ftl", params));
|
||||
result.put("repository", freemarkerTool.processString("code-generator/jpa/repository.ftl", params));
|
||||
result.put("jpacontroller", freemarkerTool.processString("code-generator/jpa/jpacontroller.ftl", params));
|
||||
//jdbc template
|
||||
result.put("jtdao", freemarkerTool.processString("code-generator/jdbc-template/jtdao.ftl", params));
|
||||
result.put("jtdaoimpl", freemarkerTool.processString("code-generator/jdbc-template/jtdaoimpl.ftl", params));
|
||||
//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));
|
||||
//util
|
||||
result.put("util", freemarkerTool.processString("code-generator/util/util.ftl", params));
|
||||
result.put("json", freemarkerTool.processString("code-generator/util/json.ftl", params));
|
||||
result.put("xml", freemarkerTool.processString("code-generator/util/xml.ftl", params));
|
||||
//sql generate
|
||||
result.put("select", freemarkerTool.processString("code-generator/sql/select.ftl", params));
|
||||
result.put("insert", freemarkerTool.processString("code-generator/sql/insert.ftl", params));
|
||||
result.put("update", freemarkerTool.processString("code-generator/sql/update.ftl", params));
|
||||
result.put("delete", freemarkerTool.processString("code-generator/sql/delete.ftl", params));
|
||||
|
||||
// 计算,生成代码行数
|
||||
int lineNum = 0;
|
||||
for (Map.Entry<String, String> item: result.entrySet()) {
|
||||
if (item.getValue() != null) {
|
||||
lineNum += StringUtils.countMatches(item.getValue(), "\n");
|
||||
}
|
||||
}
|
||||
log.info("生成代码行数:{}", lineNum);
|
||||
//测试环境可自行开启
|
||||
//log.info("生成代码数据:{}", result);
|
||||
return new ReturnT<>(result);
|
||||
} catch (IOException | TemplateException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, "表结构解析失败"+e.getMessage());
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
|
||||
} catch (CodeGenerateException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
package com.softdev.system.generator.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Post data - ParamInfo
|
||||
* @author zhengkai.blog.csdn.net
|
||||
*/
|
||||
@Data
|
||||
public class ParamInfo {
|
||||
private String tableSql;
|
||||
private String authorName;
|
||||
private String packageName;
|
||||
private String returnUtil;
|
||||
private String nameCaseType;
|
||||
private String tinyintTransType;
|
||||
private String dataType;
|
||||
|
||||
@Data
|
||||
public static class NAME_CASE_TYPE{
|
||||
public static String CAMEL_CASE="CamelCase";
|
||||
public static String UNDER_SCORE_CASE="UnderScoreCase";
|
||||
public static String UPPER_UNDER_SCORE_CASE="UpperUnderScoreCase";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.softdev.system.generator.service;
|
||||
|
||||
import freemarker.template.TemplateException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* GeneratorService
|
||||
* @author zhengkai.blog.csdn.net
|
||||
*/
|
||||
public interface GeneratorService {
|
||||
|
||||
public Map<String,String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException;
|
||||
|
||||
}
|
||||
@ -0,0 +1,78 @@
|
||||
package com.softdev.system.generator.service;
|
||||
|
||||
import com.softdev.system.generator.util.FreemarkerTool;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* GeneratorService
|
||||
* @author zhengkai.blog.csdn.net
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class GeneratorServiceImpl implements GeneratorService {
|
||||
|
||||
@Autowired
|
||||
private FreemarkerTool freemarkerTool;
|
||||
|
||||
@Override
|
||||
public Map<String, String> getResultByParams(Map<String, Object> params) throws IOException, TemplateException {
|
||||
// result
|
||||
Map<String, String> result = new HashMap<String, String>(32);
|
||||
|
||||
//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));
|
||||
//mybatis old
|
||||
result.put("controller", freemarkerTool.processString("code-generator/mybatis/controller.ftl", params));
|
||||
result.put("service", freemarkerTool.processString("code-generator/mybatis/service.ftl", params));
|
||||
result.put("service_impl", freemarkerTool.processString("code-generator/mybatis/service_impl.ftl", params));
|
||||
result.put("mapper", freemarkerTool.processString("code-generator/mybatis/mapper.ftl", params));
|
||||
result.put("mybatis", freemarkerTool.processString("code-generator/mybatis/mybatis.ftl", params));
|
||||
result.put("model", freemarkerTool.processString("code-generator/mybatis/model.ftl", params));
|
||||
//jpa
|
||||
result.put("entity", freemarkerTool.processString("code-generator/jpa/entity.ftl", params));
|
||||
result.put("repository", freemarkerTool.processString("code-generator/jpa/repository.ftl", params));
|
||||
result.put("jpacontroller", freemarkerTool.processString("code-generator/jpa/jpacontroller.ftl", params));
|
||||
//jdbc template
|
||||
result.put("jtdao", freemarkerTool.processString("code-generator/jdbc-template/jtdao.ftl", params));
|
||||
result.put("jtdaoimpl", freemarkerTool.processString("code-generator/jdbc-template/jtdaoimpl.ftl", params));
|
||||
//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));
|
||||
//util
|
||||
result.put("util", freemarkerTool.processString("code-generator/util/util.ftl", params));
|
||||
result.put("json", freemarkerTool.processString("code-generator/util/json.ftl", params));
|
||||
result.put("xml", freemarkerTool.processString("code-generator/util/xml.ftl", params));
|
||||
//sql generate
|
||||
result.put("select", freemarkerTool.processString("code-generator/sql/select.ftl", params));
|
||||
result.put("insert", freemarkerTool.processString("code-generator/sql/insert.ftl", params));
|
||||
result.put("update", freemarkerTool.processString("code-generator/sql/update.ftl", params));
|
||||
result.put("delete", freemarkerTool.processString("code-generator/sql/delete.ftl", params));
|
||||
|
||||
// 计算,生成代码行数
|
||||
/*int lineNum = 0;
|
||||
for (Map.Entry<String, String> item: result.entrySet()) {
|
||||
if (item.getValue() != null) {
|
||||
lineNum += StringUtils.countMatches(item.getValue(), "\n");
|
||||
}
|
||||
}
|
||||
log.info("生成代码行数:{}", lineNum);*/
|
||||
|
||||
//测试环境可自行开启
|
||||
//log.info("生成代码数据:{}", result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@Data
|
||||
public class ApiReturnObject implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ApiReturnObject(String errorCode, Object errorMessage, Object returnObject) {
|
||||
super();
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
this.returnObject = returnObject;
|
||||
}
|
||||
public ApiReturnObject(Object errorMessage, Object returnObject) {
|
||||
super();
|
||||
this.errorMessage = errorMessage;
|
||||
this.returnObject = returnObject;
|
||||
}
|
||||
|
||||
String errorCode="00";
|
||||
Object errorMessage;
|
||||
Object returnObject;
|
||||
String pageNumber;
|
||||
String pageSize;
|
||||
String totalElements;
|
||||
String totalPages;
|
||||
|
||||
public ApiReturnObject(String pageNumber,String pageSize,String totalElements,String totalPages,String errorCode, Object errorMessage, Object returnObject) {
|
||||
super();
|
||||
this.pageNumber = pageNumber;
|
||||
this.errorCode = errorCode;
|
||||
this.errorMessage = errorMessage;
|
||||
this.returnObject = returnObject;
|
||||
this.pageSize = pageSize;
|
||||
this.totalElements = totalElements;
|
||||
this.totalPages = totalPages;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiReturnUtil implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static ApiReturnObject error(Object errorMessage) {
|
||||
System.out.println(errorMessage);
|
||||
List<Object> object=new ArrayList<Object>();
|
||||
return new ApiReturnObject("01",errorMessage,object);
|
||||
}
|
||||
public static ApiReturnObject error(Object errorMessage, Object returnObject) {
|
||||
List<Object> object=new ArrayList<Object>();
|
||||
object.add(returnObject);
|
||||
return new ApiReturnObject("01",errorMessage,object);
|
||||
}
|
||||
public static ApiReturnObject success(Object returnObject) {
|
||||
if(returnObject instanceof java.util.List){
|
||||
return new ApiReturnObject("00","success",returnObject);
|
||||
}else {
|
||||
List<Object> object=new ArrayList<Object>();
|
||||
object.add(returnObject);
|
||||
return new ApiReturnObject("00","success",object);
|
||||
}
|
||||
}
|
||||
public static ApiReturnObject success(Object errorMessage, Object returnObject) {
|
||||
if(returnObject instanceof java.util.List){
|
||||
return new ApiReturnObject("00",errorMessage,returnObject);
|
||||
}else {
|
||||
List<Object> object=new ArrayList<Object>();
|
||||
object.add(returnObject);
|
||||
return new ApiReturnObject("00",errorMessage,object);
|
||||
}
|
||||
}
|
||||
public static ApiReturnObject pageManual(Integer pageNumber, Integer pageSize,Integer countNum, List returnObject) {
|
||||
return new ApiReturnObject(pageNumber+"",pageSize+"",countNum+"",getTotalPages(countNum, pageSize),"00","success",returnObject);
|
||||
}
|
||||
|
||||
public static String getTotalPages(Integer countNum, Integer pageSize) {
|
||||
if((countNum%pageSize)==0) {
|
||||
return ((countNum/pageSize))+"";
|
||||
}else {
|
||||
return ((countNum/pageSize)+1)+"";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class BasePath {
|
||||
protected static String contextPath = null;
|
||||
protected static String basePath = null;
|
||||
protected static String realPath = null;
|
||||
|
||||
public static String getBasePath(HttpServletRequest request) {
|
||||
contextPath = request.getContextPath();
|
||||
basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+contextPath+"/";
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public static String getRealPath(HttpServletRequest request, String path) {
|
||||
ServletContext context = request.getSession().getServletContext();
|
||||
realPath = context.getRealPath(path);
|
||||
realPath = context.getRealPath(path)+"\\";
|
||||
return realPath;
|
||||
}
|
||||
|
||||
public static String getMyRealPath(HttpServletRequest request, String path) {
|
||||
ServletContext context = request.getSession().getServletContext();
|
||||
realPath = context.getRealPath(path);
|
||||
realPath = context.getRealPath(path);
|
||||
return realPath;
|
||||
}
|
||||
}
|
||||
@ -1,57 +0,0 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
/**
|
||||
* string tool
|
||||
*
|
||||
* @author xuxueli 2018-05-02 20:43:25
|
||||
*/
|
||||
public class StringPlusUtils {
|
||||
|
||||
/**
|
||||
* 首字母大写
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String upperCaseFirst(String str) {
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 首字母小写
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static String lowerCaseFirst(String str) {
|
||||
return str.substring(0, 1).toLowerCase() + str.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线,转换为驼峰式
|
||||
*
|
||||
* @param underscoreName
|
||||
* @return
|
||||
*/
|
||||
public static String underlineToCamelCase(String underscoreName) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
if (underscoreName != null && underscoreName.trim().length() > 0) {
|
||||
boolean flag = false;
|
||||
for (int i = 0; i < underscoreName.length(); i++) {
|
||||
char ch = underscoreName.charAt(i);
|
||||
if ("_".charAt(0) == ch) {
|
||||
flag = true;
|
||||
} else {
|
||||
if (flag) {
|
||||
result.append(Character.toUpperCase(ch));
|
||||
flag = false;
|
||||
} else {
|
||||
result.append(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,8 +1,14 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.softdev.system.generator.entity.ClassInfo;
|
||||
import com.softdev.system.generator.entity.FieldInfo;
|
||||
import com.softdev.system.generator.entity.ParamInfo;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
@ -13,24 +19,32 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author xuxueli 2018-05-02 21:10:45
|
||||
* @modify zhengk/moshow 20180913
|
||||
* @author zhengkai.blog.csdn.net
|
||||
*/
|
||||
public class TableParseUtil {
|
||||
|
||||
/**
|
||||
* 解析建表SQL生成代码(model-dao-xml)
|
||||
*
|
||||
* @param tableSql
|
||||
* @param paramInfo
|
||||
* @return
|
||||
*/
|
||||
public static ClassInfo processTableIntoClassInfo(String tableSql, boolean isUnderLineToCamelCase,String tinyintTransType)
|
||||
public static ClassInfo processTableIntoClassInfo(ParamInfo paramInfo)
|
||||
throws IOException {
|
||||
//process the param
|
||||
String tableSql=paramInfo.getTableSql();
|
||||
String nameCaseType=paramInfo.getNameCaseType();
|
||||
String tinyintTransType=paramInfo.getTinyintTransType();
|
||||
|
||||
if (tableSql==null || tableSql.trim().length()==0) {
|
||||
throw new CodeGenerateException("Table structure can not be empty.");
|
||||
}
|
||||
//deal with special character
|
||||
tableSql = tableSql.trim().replaceAll("'","`").replaceAll("\"","`").replaceAll(",",",").toLowerCase();
|
||||
|
||||
//deal with java string copy \n"
|
||||
System.out.println(tableSql);
|
||||
tableSql = tableSql.trim().replaceAll("n`","").replaceAll("\\+","").replaceAll("``","`").replaceAll("\\\\","");
|
||||
System.out.println(tableSql);
|
||||
// table Name
|
||||
String tableName = null;
|
||||
if (tableSql.contains("TABLE") && tableSql.contains("(")) {
|
||||
@ -164,14 +178,18 @@ public class TableParseUtil {
|
||||
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
||||
// field Name
|
||||
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
||||
String fieldName;
|
||||
if(isUnderLineToCamelCase){
|
||||
String fieldName=null;
|
||||
if(ParamInfo.NAME_CASE_TYPE.CAMEL_CASE.equals(nameCaseType)){
|
||||
fieldName = StringUtils.lowerCaseFirst(StringUtils.underlineToCamelCase(columnName));
|
||||
if (fieldName.contains("_")) {
|
||||
fieldName = fieldName.replaceAll("_", "");
|
||||
}
|
||||
}else {
|
||||
}else if(ParamInfo.NAME_CASE_TYPE.UNDER_SCORE_CASE.equals(nameCaseType)){
|
||||
fieldName = StringUtils.lowerCaseFirst(columnName);
|
||||
}else if(ParamInfo.NAME_CASE_TYPE.UPPER_UNDER_SCORE_CASE.equals(nameCaseType)){
|
||||
fieldName = StringUtils.lowerCaseFirst(columnName.toUpperCase());
|
||||
}else{
|
||||
fieldName=columnName;
|
||||
}
|
||||
|
||||
// field class
|
||||
@ -290,5 +308,118 @@ public class TableParseUtil {
|
||||
|
||||
return codeJavaInfo;
|
||||
}
|
||||
/**
|
||||
* parse JSON
|
||||
* @param paramInfo
|
||||
* @return
|
||||
*/
|
||||
public static ClassInfo processJsonToClassInfo(ParamInfo paramInfo){
|
||||
ClassInfo codeJavaInfo = new ClassInfo();
|
||||
codeJavaInfo.setTableName("JsonDto");
|
||||
codeJavaInfo.setClassName("JsonDto");
|
||||
codeJavaInfo.setClassComment("JsonDto");
|
||||
|
||||
//support children json if forget to add '{' in front of json
|
||||
if(paramInfo.getTableSql().trim().startsWith("\"")){
|
||||
paramInfo.setTableSql("{"+paramInfo.getTableSql());
|
||||
}
|
||||
if(JSON.isValid(paramInfo.getTableSql())){
|
||||
if(paramInfo.getTableSql().trim().startsWith("{")){
|
||||
JSONObject jsonObject = JSONObject.parseObject(paramInfo.getTableSql().trim());
|
||||
//parse FieldList by JSONObject
|
||||
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonObject));
|
||||
}else if(paramInfo.getTableSql().trim().startsWith("[")){
|
||||
JSONArray jsonArray=JSONArray.parseArray(paramInfo.getTableSql().trim());
|
||||
//parse FieldList by JSONObject
|
||||
codeJavaInfo.setFieldList(processJsonObjectToFieldList(jsonArray.getJSONObject(0)));
|
||||
}
|
||||
}
|
||||
|
||||
return codeJavaInfo;
|
||||
}
|
||||
/**
|
||||
* parse SQL by regex
|
||||
* @author https://github.com/ydq
|
||||
* @param paramInfo
|
||||
* @return
|
||||
*/
|
||||
public static ClassInfo processTableToClassInfoByRegex(ParamInfo paramInfo){
|
||||
// field List
|
||||
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||
//return classInfo
|
||||
ClassInfo codeJavaInfo = new ClassInfo();
|
||||
|
||||
//匹配整个ddl,将ddl分为表名,列sql部分,表注释
|
||||
String DDL_PATTEN_STR="\\s*create\\s+table\\s+(?<tableName>\\S+)[^\\(]*\\((?<columnsSQL>[\\s\\S]+)\\)[^\\)]+?(comment\\s*(=|on\\s+table)\\s*'(?<tableComment>.*?)'\\s*;?)?$";
|
||||
|
||||
Pattern DDL_PATTERN = Pattern.compile(DDL_PATTEN_STR, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
//匹配列sql部分,分别解析每一列的列名 类型 和列注释
|
||||
String COL_PATTERN_STR="\\s*(?<fieldName>\\S+)\\s+(?<fieldType>\\w+)\\s*(?:\\([\\s\\d,]+\\))?((?!comment).)*(comment\\s*'(?<fieldComment>.*?)')?\\s*(,|$)";
|
||||
|
||||
Pattern COL_PATTERN = Pattern.compile(COL_PATTERN_STR, Pattern.CASE_INSENSITIVE);
|
||||
|
||||
Matcher matcher = DDL_PATTERN.matcher(paramInfo.getTableSql().trim());
|
||||
if (matcher.find()){
|
||||
String tableName = matcher.group("tableName");
|
||||
String tableComment = matcher.group("tableComment");
|
||||
codeJavaInfo.setTableName(tableName.replaceAll("'",""));
|
||||
codeJavaInfo.setClassName(tableName.replaceAll("'",""));
|
||||
codeJavaInfo.setClassComment(tableComment.replaceAll("'",""));
|
||||
String columnsSQL = matcher.group("columnsSQL");
|
||||
if (columnsSQL != null && columnsSQL.length() > 0){
|
||||
Matcher colMatcher = COL_PATTERN.matcher(columnsSQL);
|
||||
while (colMatcher.find()){
|
||||
String fieldName = colMatcher.group("fieldName");
|
||||
String fieldType = colMatcher.group("fieldType");
|
||||
String fieldComment = colMatcher.group("fieldComment");
|
||||
if (!"key".equalsIgnoreCase(fieldType)){
|
||||
FieldInfo fieldInfo = new FieldInfo();
|
||||
fieldInfo.setFieldName(fieldName.replaceAll("'",""));
|
||||
fieldInfo.setColumnName(fieldName.replaceAll("'",""));
|
||||
fieldInfo.setFieldClass(fieldType.replaceAll("'",""));
|
||||
fieldInfo.setFieldComment(fieldComment.replaceAll("'",""));
|
||||
fieldList.add(fieldInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
codeJavaInfo.setFieldList(fieldList);
|
||||
}
|
||||
return codeJavaInfo;
|
||||
}
|
||||
public static List<FieldInfo> processJsonObjectToFieldList(JSONObject jsonObject){
|
||||
// field List
|
||||
List<FieldInfo> fieldList = new ArrayList<FieldInfo>();
|
||||
jsonObject.keySet().stream().forEach(jsonField->{
|
||||
FieldInfo fieldInfo = new FieldInfo();
|
||||
fieldInfo.setFieldName(jsonField);
|
||||
fieldInfo.setColumnName(jsonField);
|
||||
fieldInfo.setFieldClass(String.class.getSimpleName());
|
||||
fieldInfo.setFieldComment("father:"+jsonField);
|
||||
fieldList.add(fieldInfo);
|
||||
if(jsonObject.get(jsonField) instanceof JSONArray){
|
||||
jsonObject.getJSONArray(jsonField).stream().forEach(arrayObject->{
|
||||
FieldInfo fieldInfo2 = new FieldInfo();
|
||||
fieldInfo2.setFieldName(arrayObject.toString());
|
||||
fieldInfo2.setColumnName(arrayObject.toString());
|
||||
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||
fieldInfo2.setFieldComment("children:"+arrayObject.toString());
|
||||
fieldList.add(fieldInfo2);
|
||||
});
|
||||
}else if(jsonObject.get(jsonField) instanceof JSONObject){
|
||||
jsonObject.getJSONObject(jsonField).keySet().stream().forEach(arrayObject->{
|
||||
FieldInfo fieldInfo2 = new FieldInfo();
|
||||
fieldInfo2.setFieldName(arrayObject.toString());
|
||||
fieldInfo2.setColumnName(arrayObject.toString());
|
||||
fieldInfo2.setFieldClass(String.class.getSimpleName());
|
||||
fieldInfo2.setFieldComment("children:"+arrayObject.toString());
|
||||
fieldList.add(fieldInfo2);
|
||||
});
|
||||
}
|
||||
});
|
||||
if(fieldList.size()<1){
|
||||
throw new CodeGenerateException("JSON解析失败");
|
||||
}
|
||||
return fieldList;
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +56,8 @@
|
||||
"packageName":$("#packageName").val(),
|
||||
"returnUtil":$("#returnUtil").val(),
|
||||
"authorName":$("#authorName").val(),
|
||||
"isUnderLineToCamelCase":$("#isUnderLineToCamelCase").val()
|
||||
"dataType":$("#dataType").val(),
|
||||
"nameCaseType":$("#nameCaseType").val()
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
@ -66,7 +67,7 @@
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
$.toast("√ 代码生成成功");
|
||||
} else {
|
||||
$.toast("× 代码生成失败");
|
||||
$.toast("× 代码生成失败 :"+data.msg);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -148,6 +149,15 @@
|
||||
<input type="text" class="form-control" id="packageName" name="packageName" placeholder="com.softdev.system">
|
||||
</div>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">数据类型</span>
|
||||
</div>
|
||||
<select type="text" class="form-control" id="dataType"
|
||||
name="dataType">
|
||||
<option value="sql">sql</option>
|
||||
<option value="json">json</option>
|
||||
<option value="sql-regex">sql-regex</option>
|
||||
</select>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">tinyint转换类型</span>
|
||||
</div>
|
||||
@ -157,14 +167,16 @@
|
||||
<option value="Boolean">Boolean</option>
|
||||
<option value="Integer">Integer</option>
|
||||
<option value="int">int</option>
|
||||
<option value="String">String</option>
|
||||
</select>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">是否转换下划线为驼峰</span>
|
||||
<span class="input-group-text">命名转换规则</span>
|
||||
</div>
|
||||
<select type="text" class="form-control" id="isUnderLineToCamelCase"
|
||||
name="isUnderLineToCamelCase">
|
||||
<option value="true">转换</option>
|
||||
<option value="false">不转换</option>
|
||||
<select type="text" class="form-control" id="nameCaseType"
|
||||
name="nameCaseType">
|
||||
<option value="CamelCase">驼峰</option>
|
||||
<option value="UnderScoreCase">下划线</option>
|
||||
<#--<option value="UpperUnderScoreCase">大写下划线</option>-->
|
||||
</select>
|
||||
</div>
|
||||
<textarea id="ddlSqlArea" placeholder="请输入表结构信息..." class="form-control btn-lg" style="height: 250px;">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user