mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
beetl supoort
This commit is contained in:
parent
5a471124bc
commit
bc5e93860d
@ -6,7 +6,7 @@
|
||||
|
||||
SpringBootCodeGenerator
|
||||
----
|
||||
基于SpringBoot2+Freemarker的代码生成器,用DDL语句生成JPA/JdbcTemplate/Mybatis相关代码,支持mysql/oracle/pgsql三大数据库。目前以JPA的为主,各大模板也在陆续优化。欢迎大家提交模板和交流想法!
|
||||
基于SpringBoot2+Freemarker的代码生成器,用DDL SQL语句生成JPA/JdbcTemplate/Mybatis相关代码,支持mysql/oracle/pgsql三大数据库。目前以JPA的为主,各大模板也在陆续优化。欢迎大家提交模板和交流想法!
|
||||
<br><br>
|
||||
另外,感谢bejson三叔将他部署在http://java.bejson.com/generator上
|
||||
<br><br>
|
||||
@ -16,6 +16,7 @@ SpringBootCodeGenerator
|
||||
<tr><td>CSDN博客</td> <td>http://blog.csdn.net/moshowgame</td></tr>
|
||||
<tr><td></td> <td></td></tr>
|
||||
<tr><td>更新日期</td> <td>更新内容</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>
|
||||
|
||||
@ -75,6 +75,10 @@ public class IndexController {
|
||||
result.put("jtdao", freemarkerTool.processString("xxl-code-generator/jtdao.ftl", params));
|
||||
result.put("jtdaoimpl", freemarkerTool.processString("xxl-code-generator/jtdaoimpl.ftl", params));
|
||||
|
||||
result.put("beetlmd", freemarkerTool.processString("xxl-code-generator/beetlmd.ftl", params));
|
||||
result.put("beetlentity", freemarkerTool.processString("xxl-code-generator/beetlentity.ftl", params));
|
||||
result.put("beetlcontroller", freemarkerTool.processString("xxl-code-generator/beetlcontroller.ftl", params));
|
||||
|
||||
// 计算,生成代码行数
|
||||
int lineNum = 0;
|
||||
for (Map.Entry<String, String> item: result.entrySet()) {
|
||||
|
||||
@ -1,5 +1,13 @@
|
||||
package com.softdev.system.generator.util;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.softdev.system.generator.entity.ClassInfo;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* string tool
|
||||
*
|
||||
@ -54,4 +62,26 @@ public class StringUtils {
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/*String tableSql="comment on column check_info is `体检信息` ,comment on column check_xxxxx is `体检信息xx` ";
|
||||
String fieldName="check_info";
|
||||
String fieldComment="aaa";
|
||||
Matcher columnCommentMatcher = Pattern.compile(fieldName+" is `").matcher(tableSql); // "\\{(.*?)\\}"
|
||||
while(columnCommentMatcher.find()){
|
||||
String columnCommentTmp = columnCommentMatcher.group();
|
||||
System.out.println(columnCommentTmp);
|
||||
fieldComment = tableSql.substring(tableSql.indexOf(columnCommentTmp)+columnCommentTmp.length()).trim();
|
||||
fieldComment = fieldComment.substring(0,fieldComment.indexOf("`")).trim();
|
||||
}
|
||||
System.out.println(fieldComment);*/
|
||||
/*ClassInfo classInfo=new ClassInfo();
|
||||
classInfo.setClassComment("xxxx");
|
||||
classInfo.setTableName("2b");
|
||||
ClassInfo newInfo=new ClassInfo();
|
||||
classInfo.setClassName("bbbb");
|
||||
classInfo.setTableName("3b");
|
||||
//以new为主
|
||||
BeanUtil.copyProperties(classInfo,newInfo,true, CopyOptions.create());
|
||||
System.out.println(JSON.toJSONString(newInfo));*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,5 +138,23 @@ $(function () {
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
}
|
||||
});
|
||||
$('#beetlcontroller').click(function () {
|
||||
if(!$.isEmptyObject(codeData)) {
|
||||
genCodeArea.setValue(codeData.beetlcontroller);
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
}
|
||||
});
|
||||
$('#beetlmd').click(function () {
|
||||
if(!$.isEmptyObject(codeData)) {
|
||||
genCodeArea.setValue(codeData.beetlmd);
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
}
|
||||
});
|
||||
$('#beetlentity').click(function () {
|
||||
if(!$.isEmptyObject(codeData)) {
|
||||
genCodeArea.setValue(codeData.beetlentity);
|
||||
genCodeArea.setSize('auto', 'auto');
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
@ -30,8 +30,7 @@
|
||||
<div class="jumbotron">
|
||||
<div class="container">
|
||||
<h1>Spring Boot Code Generator!</h1>
|
||||
<p>基于<code>SpringBoot2</code>+<code>xxl-codegenerator</code>的代码生成器。用DDL语句生成<code>JPA</code>/<code>JdbcTemplate</code>/<code>Mybatis</code>相关代码,目前以<code>JPA</code>的为主,各大<code>模板</code>也在陆续优化。如果发现有SQL语句不能识别,请<a href="https://github.com/moshowgame/SpringBootCodeGenerator/issues">留言</a>给我分析,谢谢!
|
||||
|
||||
基于<code>SpringBoot2</code>+<code>Freemarker</code>的代码生成器,用<code>DDL SQL</code>语句生成<code>JPA</code>/<code>JdbcTemplate</code>/<code>Mybatis</code>相关代码,支持<code>mysql</code>/<code>oracle</code>/<code>pgsql</code>三大数据库。目前以<code>JPA</code>的为主,各大模板也在陆续优化。欢迎大家提交模板和交流想法,如果发现有SQL语句不能识别,请<a href="https://github.com/moshowgame/SpringBootCodeGenerator/issues">留言</a>给我分析,谢谢!
|
||||
</p>
|
||||
<div class="input-group mb-3">
|
||||
<div class="input-group-prepend">
|
||||
@ -65,6 +64,18 @@ CREATE TABLE `userinfo` (
|
||||
<button type="button" class="btn btn-default" id="jtdao">dao</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<div class="input-group-text" id="btnGroupAddon">BeetlSQL</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group" aria-label="First group">
|
||||
<button type="button" class="btn btn-default" id="beetlentity">entity(lombok)</button>
|
||||
<button type="button" class="btn btn-default" id="beetlmd">beetlmd</button>
|
||||
<button type="button" class="btn btn-default" id="beetlcontroller">beetlcontroller</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
@ -72,10 +83,10 @@ CREATE TABLE `userinfo` (
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group" aria-label="First group">
|
||||
<button type="button" class="btn btn-default" id="swaggerui">swaggerui</button>
|
||||
<button type="button" class="btn btn-default" id="swaggerui">swagger-ui</button>
|
||||
<button type="button" class="btn btn-default" id="entity">entity</button>
|
||||
<button type="button" class="btn btn-default" id="repository">repository</button>
|
||||
<button type="button" class="btn btn-default" id="jpacontroller">jpacontroller</button>
|
||||
<button type="button" class="btn btn-default" id="jpacontroller">controller</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-toolbar mb-3" role="toolbar" aria-label="Toolbar with button groups">
|
||||
@ -85,7 +96,7 @@ CREATE TABLE `userinfo` (
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn-group mr-2" role="group" aria-label="First group">
|
||||
<button type="button" class="btn btn-default" id="model">model</button>
|
||||
<button type="button" class="btn btn-default" id="model">model(set/get)</button>
|
||||
<button type="button" class="btn btn-default" id="mybatis">mybatis</button>
|
||||
<button type="button" class="btn btn-default" id="dao">dao</button>
|
||||
<button type="button" class="btn btn-default" id="service">service</button>
|
||||
|
||||
@ -0,0 +1,73 @@
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${classInfo.classComment}
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||
public class ${classInfo.className}Controller {
|
||||
|
||||
@Autowired
|
||||
private SQLManager sqlManager;
|
||||
|
||||
/**
|
||||
* 新增或编辑
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,${classInfo.className?uncap_first}.getId());
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
sqlManager.updateById(${classInfo.className?uncap_first});
|
||||
return ApiReturnUtil.success("编辑成功");
|
||||
}else{
|
||||
sqlManager.insert(${classInfo.className?uncap_first});
|
||||
return ApiReturnUtil.error("保存成功");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping("/delete")
|
||||
public Object delete(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id);
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
sqlManager.deleteById(id);
|
||||
return ApiReturnUtil.success("删除成功");
|
||||
}else{
|
||||
return ApiReturnUtil.error("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询
|
||||
*/
|
||||
@PostMapping("/find")
|
||||
public Object find(int id){
|
||||
${classInfo.className} ${classInfo.className?uncap_first}=sqlManager.unique(${classInfo.className}.class,id);
|
||||
if(${classInfo.className?uncap_first}!=null){
|
||||
return ApiReturnUtil.success(${classInfo.className?uncap_first});
|
||||
}else{
|
||||
return ApiReturnUtil.error("没有找到该对象");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
@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) {
|
||||
List<${classInfo.className}> list = sqlManager.query(${classInfo.className}.class).select();
|
||||
return ApiReturnUtil.error(list);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
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
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
/**
|
||||
* ${fieldItem.fieldComment}
|
||||
*/
|
||||
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
sample
|
||||
===
|
||||
|
||||
select #use("cols")# from ${classInfo.tableName} where #use("condition")#
|
||||
|
||||
cols
|
||||
===
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
updateSample
|
||||
===
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
`${fieldItem.columnName}=#${fieldItem.fieldName}#`<#if fieldItem_has_next>,</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
|
||||
condition
|
||||
===
|
||||
1 = 1
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
@if(!isEmpty(${fieldItem.fieldName})){
|
||||
and `${fieldItem.columnName}`=#${fieldItem.fieldName}#
|
||||
@}
|
||||
</#list>
|
||||
</#if>
|
||||
@ -1,10 +1,3 @@
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.fieldClass == "Date">
|
||||
<#assign importDdate = true />
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
import javax.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@ -47,7 +47,7 @@ public class ${classInfo.className}Controller {
|
||||
* 查询
|
||||
*/
|
||||
@GetMapping("/find")
|
||||
public Object load(int id){
|
||||
public Object find(int id){
|
||||
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||
if(${classInfo.className?uncap_first}.isPresent()){
|
||||
return ApiReturnUtil.success(${classInfo.className?uncap_first}.get());
|
||||
|
||||
@ -39,7 +39,7 @@ public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao
|
||||
|
||||
@Override
|
||||
public ${classInfo.className} findById(int id) {
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break ></#if></#list></#if> = ?", new Object[]{id}, new BeanPropertyRowMapper(${classInfo.className}.class));
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName} where <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index = 0>${fieldItem.columnName}=?<#break ></#if></#list></#if> = ?", new Object[]{id}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class));
|
||||
if(list!=null && list.size()>0){
|
||||
${classInfo.className} ${classInfo.className?uncap_first} = list.get(0);
|
||||
return ${classInfo.className?uncap_first};
|
||||
@ -50,7 +50,7 @@ public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao
|
||||
|
||||
@Override
|
||||
public List<${classInfo.className}> findAllList(Map<String,Object> params) {
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName}", new Object[]{}, new BeanPropertyRowMapper(${classInfo.className}.class));
|
||||
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.tableName}", new Object[]{}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class));
|
||||
if(list!=null && list.size()>0){
|
||||
return list;
|
||||
}else{
|
||||
|
||||
@ -1,10 +1,3 @@
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
<#if fieldItem.fieldClass == "Date">
|
||||
<#assign importDdate = true />
|
||||
</#if>
|
||||
</#list>
|
||||
</#if>
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -14,7 +7,7 @@ import java.util.List;
|
||||
* @author ${authorName} ${.now?string('yyyy-MM-dd')}
|
||||
*/
|
||||
public class ${classInfo.className} implements Serializable {
|
||||
private static final long serialVersionUID = 42L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||
<#list classInfo.fieldList as fieldItem >
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user