mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2025-12-26 05:48:33 +08:00
new jpa controller mode
This commit is contained in:
parent
21ce2fc7fe
commit
40b052d164
@ -8,6 +8,7 @@ import freemarker.template.TemplateException;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
@ -26,7 +27,7 @@ import java.util.Map;
|
|||||||
public class IndexController {
|
public class IndexController {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(IndexController.class);
|
private static final Logger logger = LoggerFactory.getLogger(IndexController.class);
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private FreemarkerTool freemarkerTool;
|
private FreemarkerTool freemarkerTool;
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
@ -65,6 +66,8 @@ public class IndexController {
|
|||||||
result.put("entity_code", freemarkerTool.processString("xxl-code-generator/entity.ftl", params));
|
result.put("entity_code", freemarkerTool.processString("xxl-code-generator/entity.ftl", params));
|
||||||
result.put("repository_code", freemarkerTool.processString("xxl-code-generator/repository.ftl", params));
|
result.put("repository_code", freemarkerTool.processString("xxl-code-generator/repository.ftl", params));
|
||||||
|
|
||||||
|
result.put("jpacontroller_code", freemarkerTool.processString("xxl-code-generator/jpacontroller.ftl", params));
|
||||||
|
|
||||||
// 计算,生成代码行数
|
// 计算,生成代码行数
|
||||||
int lineNum = 0;
|
int lineNum = 0;
|
||||||
for (Map.Entry<String, String> item: result.entrySet()) {
|
for (Map.Entry<String, String> item: result.entrySet()) {
|
||||||
|
|||||||
@ -30,7 +30,18 @@ $(function () {
|
|||||||
var model_ide;
|
var model_ide;
|
||||||
var entity_ide;
|
var entity_ide;
|
||||||
var repository_ide;
|
var repository_ide;
|
||||||
|
var jpacontroller_ide;
|
||||||
function initCodeArea(){
|
function initCodeArea(){
|
||||||
|
jpacontroller_ide = CodeMirror.fromTextArea(document.getElementById("jpacontroller_ide"), {
|
||||||
|
lineNumbers: true,
|
||||||
|
matchBrackets: true,
|
||||||
|
mode: "text/x-java",
|
||||||
|
lineWrapping:true,
|
||||||
|
readOnly:true,
|
||||||
|
foldGutter: true,
|
||||||
|
gutters:["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
|
||||||
|
});
|
||||||
|
jpacontroller_ide.setSize('auto','auto');
|
||||||
|
|
||||||
// controller_ide
|
// controller_ide
|
||||||
controller_ide = CodeMirror.fromTextArea(document.getElementById("controller_ide"), {
|
controller_ide = CodeMirror.fromTextArea(document.getElementById("controller_ide"), {
|
||||||
@ -173,6 +184,9 @@ $(function () {
|
|||||||
|
|
||||||
repository_ide.setValue(data.data.repository_code);
|
repository_ide.setValue(data.data.repository_code);
|
||||||
repository_ide.setSize('auto','auto');
|
repository_ide.setSize('auto','auto');
|
||||||
|
|
||||||
|
jpacontroller_ide.setValue(data.data.jpacontroller_code);
|
||||||
|
jpacontroller_ide.setSize('auto','auto');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -51,7 +51,36 @@ CREATE TABLE `userinfo` (
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<#-- JPA生成代码 -->
|
||||||
|
<div class="nav-tabs-custom">
|
||||||
|
<!-- Tabs within a box -->
|
||||||
|
<ul class="nav nav-tabs pull-right">
|
||||||
|
<li class="pull-left header">JPA版生成代码</li>
|
||||||
|
|
||||||
|
<li><a href="#entity" data-toggle="tab">Entity</a></li>
|
||||||
|
<li><a href="#repository" data-toggle="tab">Repository</a></li>
|
||||||
|
<li><a href="#jpacontroller" data-toggle="tab">JpaController</a></li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content no-padding">
|
||||||
|
|
||||||
|
<div class="chart tab-pane active" id="entity">
|
||||||
|
<div class="box-body">
|
||||||
|
Entity:<textarea id="entity_ide" ></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="chart tab-pane active" id="repository" >
|
||||||
|
<div class="box-body ">
|
||||||
|
Repository:<textarea id="repository_ide" ></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="chart tab-pane active" id="jpacontroller" >
|
||||||
|
<div class="box-body ">
|
||||||
|
Repository:<textarea id="jpacontroller_ide" ></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<#-- Mybatis生成代码 -->
|
<#-- Mybatis生成代码 -->
|
||||||
<div class="nav-tabs-custom">
|
<div class="nav-tabs-custom">
|
||||||
@ -100,30 +129,7 @@ CREATE TABLE `userinfo` (
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<#-- JPA生成代码 -->
|
|
||||||
<div class="nav-tabs-custom">
|
|
||||||
<!-- Tabs within a box -->
|
|
||||||
<ul class="nav nav-tabs pull-right">
|
|
||||||
<li class="pull-left header">JPA版生成代码</li>
|
|
||||||
|
|
||||||
<li><a href="#entity" data-toggle="tab">Entity</a></li>
|
|
||||||
<li><a href="#repository" data-toggle="tab">Repository</a></li>
|
|
||||||
|
|
||||||
</ul>
|
|
||||||
<div class="tab-content no-padding">
|
|
||||||
|
|
||||||
<div class="chart tab-pane active" id="entity">
|
|
||||||
<div class="box-body">
|
|
||||||
Entity:<textarea id="entity_ide" ></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="chart tab-pane active" id="repository" >
|
|
||||||
<div class="box-body ">
|
|
||||||
Repository:<textarea id="repository_ide" ></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -0,0 +1,71 @@
|
|||||||
|
import org.springframework.stereotype.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ${classInfo.classComment}
|
||||||
|
*
|
||||||
|
* Created by by-health on '${.now?string('yyyy-MM-dd HH:mm:ss')}'.
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||||
|
public class ${classInfo.className}Controller {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ${classInfo.className}Respository ${classInfo.className?uncap_first}Respository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或编辑
|
||||||
|
*/
|
||||||
|
@RequestMapping("/save")
|
||||||
|
public Object save(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||||
|
return ${classInfo.className?uncap_first}Respository.save(${classInfo.className?uncap_first});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@RequestMapping("/delete")
|
||||||
|
public Object delete(int id){
|
||||||
|
return ${classInfo.className?uncap_first}Respository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*/
|
||||||
|
@RequestMapping("/find")
|
||||||
|
public Object load(int id){
|
||||||
|
return ${classInfo.className?uncap_first}Respository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@RequestMapping("/list")
|
||||||
|
public Object list(${classInfo.className} ${classInfo.className?uncap_first},
|
||||||
|
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||||
|
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||||
|
|
||||||
|
//创建匹配器,即如何使用查询条件
|
||||||
|
ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
|
||||||
|
//这里追加查询处理方式。例如xxx字段采用“包含”的方式查询
|
||||||
|
//.withMatcher("xxx", GenericPropertyMatchers.contains())
|
||||||
|
;
|
||||||
|
|
||||||
|
//创建实例
|
||||||
|
Example<${classInfo.className}> ex = Example.of(${classInfo.className?uncap_first}, matcher);
|
||||||
|
//分页构造
|
||||||
|
Pageable pageable = PageRequest.of(pageNumber,pageSize);
|
||||||
|
|
||||||
|
return ${classInfo.className?uncap_first}Respository.findAll(matcher, pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user