mirror of
https://github.com/moshowgame/SpringBootCodeGenerator.git
synced 2026-06-17 20:13:39 +08:00
Compare commits
22 Commits
3.2.0
...
2022.02.09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e968a3bfe1 | ||
|
|
cffaac2508 | ||
|
|
69a0dede9b | ||
|
|
732dd246cb | ||
|
|
d3820a2552 | ||
|
|
7e93e91478 | ||
|
|
aa38125294 | ||
|
|
adab6d7809 | ||
|
|
dac7d20eb8 | ||
|
|
482e004978 | ||
|
|
94a424ac11 | ||
|
|
f6844ee7c5 | ||
|
|
a1fc04af8c | ||
|
|
efef2aefc4 | ||
|
|
f88a8c2940 | ||
|
|
1144a2137e | ||
|
|
1c6efb400b | ||
|
|
371ff03a5f | ||
|
|
ec949f97e0 | ||
|
|
78975fc86d | ||
|
|
b387240235 | ||
|
|
ab705bfa2f |
@@ -49,7 +49,7 @@
|
|||||||
Thanks for `JetBrains` providing us the `Licenses for Open Source Development` ,[Get free access to all JetBrains tools for developing your open source project!](https://www.jetbrains.com/community/opensource/#support) .<br>
|
Thanks for `JetBrains` providing us the `Licenses for Open Source Development` ,[Get free access to all JetBrains tools for developing your open source project!](https://www.jetbrains.com/community/opensource/#support) .<br>
|
||||||
|
|
||||||
| 访问地址 | http://localhost:1234/generator |
|
| 访问地址 | http://localhost:1234/generator |
|
||||||
|:----|:----|
|
|:--------------|:--------------------------------------------------------------|
|
||||||
| BEJSON 在线地址 | https://java.bejson.com/generator |
|
| BEJSON 在线地址 | https://java.bejson.com/generator |
|
||||||
| DEVTOOLS 在线地址 | https://java.devtools.cn |
|
| DEVTOOLS 在线地址 | https://java.devtools.cn |
|
||||||
| CSDN BLOG | https://zhengkai.blog.csdn.net |
|
| CSDN BLOG | https://zhengkai.blog.csdn.net |
|
||||||
@@ -59,7 +59,11 @@ Thanks for `JetBrains` providing us the `Licenses for Open Source Development`
|
|||||||
|
|
||||||
# Update Logs
|
# Update Logs
|
||||||
| 更新日期 | 更新内容 |
|
| 更新日期 | 更新内容 |
|
||||||
|:----|:----|
|
|:------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| 2022.02.10 | 更新springboot、fastjson、lombok依赖(感谢@Abbykawai的建议)。 |
|
||||||
|
| 2022.02.09 | 新增JPA-STARP模板(感谢@starplatinum3的贡献)。 |
|
||||||
|
| 2022.01.11 | 优化mybatis的mapper文件生成(感谢@chendong的贡献)。 |
|
||||||
|
| 2021.10.31 | 优化当有索引和额外的换行时的解析逻辑(感谢@feitian124的贡献)。<br>修复部分模板参数不对应(感谢@Thixiaoxiao的贡献)。<br>新增cookie记录所需配置字段逻辑,避免重复配置(感谢@Thixiaoxiao的贡献)。 |
|
||||||
| 2021.08.07 | 新增当前模板保持功能,重新生成代码后依然会保持在当前选择模板。<br>新增renren-fast模板。 |
|
| 2021.08.07 | 新增当前模板保持功能,重新生成代码后依然会保持在当前选择模板。<br>新增renren-fast模板。 |
|
||||||
| 2021.08.05 | 解决 update 方法语法错误;调整部分语句避免sonarLint告警(感谢@Henry586的PR);<br>add swagger-yml.ftl(感谢@fuuqiu的PR);<br>支持common-mapper&修复entity和plusentity的swagger引包错误(感谢@chentianming11的PR) |
|
| 2021.08.05 | 解决 update 方法语法错误;调整部分语句避免sonarLint告警(感谢@Henry586的PR);<br>add swagger-yml.ftl(感谢@fuuqiu的PR);<br>支持common-mapper&修复entity和plusentity的swagger引包错误(感谢@chentianming11的PR) |
|
||||||
| 2021.03.24 | 修复Mybatis.XML中缺失test=关键字问题。(感谢@BWHN/YUEHUI的反馈)。 |
|
| 2021.03.24 | 修复Mybatis.XML中缺失test=关键字问题。(感谢@BWHN/YUEHUI的反馈)。 |
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ public class GeneratorController {
|
|||||||
|
|
||||||
//3.generate the code by freemarker templates with parameters . Freemarker根据参数和模板生成代码
|
//3.generate the code by freemarker templates with parameters . Freemarker根据参数和模板生成代码
|
||||||
Map<String, String> result = generatorService.getResultByParams(paramInfo.getOptions());
|
Map<String, String> result = generatorService.getResultByParams(paramInfo.getOptions());
|
||||||
|
log.info("result {}",result);
|
||||||
log.info("table:{} - time:{} ", MapUtil.getString(result,"tableName"),new Date());
|
log.info("table:{} - time:{} ", MapUtil.getString(result,"tableName"),new Date());
|
||||||
return ReturnT.ok().put("outputJson",result);
|
return ReturnT.ok().put("outputJson",result);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,7 +173,13 @@ public class TableParseUtil {
|
|||||||
String columnName = "";
|
String columnName = "";
|
||||||
columnLine = columnLine.replaceAll("`", " ").replaceAll("\"", " ").replaceAll("'", "").replaceAll(" ", " ").trim();
|
columnLine = columnLine.replaceAll("`", " ").replaceAll("\"", " ").replaceAll("'", "").replaceAll(" ", " ").trim();
|
||||||
//如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前
|
//如果遇到username varchar(65) default '' not null,这种情况,判断第一个空格是否比第一个引号前
|
||||||
|
try {
|
||||||
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
columnName = columnLine.substring(0, columnLine.indexOf(" "));
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
System.out.println("err happened: " + columnLine);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
// field Name
|
// field Name
|
||||||
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
// 2019-09-08 yj 添加是否下划线转换为驼峰的判断
|
||||||
String fieldName = null;
|
String fieldName = null;
|
||||||
|
|||||||
@@ -42,3 +42,28 @@ window.confirm = function(msg, callback){
|
|||||||
function isBlank(value) {
|
function isBlank(value) {
|
||||||
return !value || !/\S/.test(value)
|
return !value || !/\S/.test(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setCookie(key, val, expire_second) {
|
||||||
|
var d = new Date();
|
||||||
|
var expires ="";
|
||||||
|
if (expire_second){
|
||||||
|
d.setDate(d.getTime()+(expire_second*1000));
|
||||||
|
expires='; expires=' + d.toGMTSring();
|
||||||
|
}
|
||||||
|
document.cookie = key + "="+ val + expires;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCookie(name) {
|
||||||
|
var data = "";
|
||||||
|
if (document.cookie){
|
||||||
|
var arr = document.cookie.split(';');
|
||||||
|
for (var str of arr) {
|
||||||
|
var temp = str.split("=")
|
||||||
|
if (temp[0].replace(/(^\s*)/g,'') === name){
|
||||||
|
data = unescape(temp[1]);
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
@@ -123,6 +123,7 @@ const vm = new Vue({
|
|||||||
error("生成失败");
|
error("生成失败");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setAllCookie();
|
||||||
//console.log(res.outputJson);
|
//console.log(res.outputJson);
|
||||||
vm.outputJson=res.outputJson;
|
vm.outputJson=res.outputJson;
|
||||||
// console.log(vm.outputJson["bootstrap-ui"]);
|
// console.log(vm.outputJson["bootstrap-ui"]);
|
||||||
@@ -154,3 +155,41 @@ const vm = new Vue({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将所有 需要 保留历史纪录的字段写入Cookie中
|
||||||
|
*/
|
||||||
|
function setAllCookie() {
|
||||||
|
var arr = list_key_need_load();
|
||||||
|
for (var str of arr){
|
||||||
|
setOneCookie(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setOneCookie(key) {
|
||||||
|
setCookie(key, vm.formData.options[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将所有 历史纪录 重加载回页面
|
||||||
|
*/
|
||||||
|
function loadAllCookie() {
|
||||||
|
//console.log(vm);
|
||||||
|
var arr = list_key_need_load();
|
||||||
|
for (var str of arr){
|
||||||
|
loadOneCookie(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadOneCookie(key) {
|
||||||
|
if (getCookie(key)!==""){
|
||||||
|
vm.formData.options[key] = getCookie(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 所有 需要 纪录的 字段写入数组
|
||||||
|
* @returns {[string]}
|
||||||
|
*/
|
||||||
|
function list_key_need_load() {
|
||||||
|
return ["authorName","packageName","returnUtilSuccess","returnUtilFailure","ignorePrefix","tinyintTransType","timeTransType"];
|
||||||
|
}
|
||||||
|
|||||||
@@ -229,5 +229,25 @@
|
|||||||
"description": "rr-service"
|
"description": "rr-service"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"group": "jpa-starp",
|
||||||
|
"templates": [{
|
||||||
|
"id": "101",
|
||||||
|
"name": "starp-entity",
|
||||||
|
"description": "entity"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "102",
|
||||||
|
"name": "starp-repository",
|
||||||
|
"description": "repository"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "103",
|
||||||
|
"name": "starp-jpa-controller",
|
||||||
|
"description": "jpacontroller"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -19,13 +19,13 @@ public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int add(${classInfo.className} ${classInfo.className?uncap_first}) {
|
public int add(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||||
return jdbcTemplate.update("insert into ${classInfo.tableName} (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list></#if> ) values (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >?<#if fieldItem_has_next>,</#if></#list></#if> )",
|
return jdbcTemplate.update("insert into ${classInfo.originTableName} (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${fieldItem.columnName}<#if fieldItem_has_next>,</#if></#list></#if> ) values (<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >?<#if fieldItem_has_next>,</#if></#list></#if> )",
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()<#if fieldItem_has_next>,</#if></#list></#if>);
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}()<#if fieldItem_has_next>,</#if></#list></#if>);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(${classInfo.className} ${classInfo.className?uncap_first}) {
|
public int update(${classInfo.className} ${classInfo.className?uncap_first}) {
|
||||||
return jdbcTemplate.update("UPDATE ${classInfo.tableName} SET <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${fieldItem.columnName}=?<#if fieldItem_has_next>,</#if></#if></#list></#if>"
|
return jdbcTemplate.update("UPDATE ${classInfo.originTableName} SET <#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0><#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${fieldItem.columnName}=?<#if fieldItem_has_next>,</#if></#if></#list></#if>"
|
||||||
+" 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>",
|
+" 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>",
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(),</#if></#list>
|
<#list classInfo.fieldList as fieldItem ><#if fieldItem_index gt 0 >${classInfo.className?uncap_first}.get${fieldItem.fieldName?cap_first}(),</#if></#list>
|
||||||
@@ -35,12 +35,12 @@ public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(int id) {
|
public int delete(int id) {
|
||||||
return jdbcTemplate.update("DELETE 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>",id);
|
return jdbcTemplate.update("DELETE from ${classInfo.originTableName} 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>",id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ${classInfo.className} findById(int id) {
|
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}>(${classInfo.className}.class));
|
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.originTableName} 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.isEmpty() ){
|
if(list!=null && !list.isEmpty() ){
|
||||||
return list.get(0);
|
return list.get(0);
|
||||||
}else{
|
}else{
|
||||||
@@ -50,7 +50,7 @@ public class ${classInfo.className}DaoImpl implements I${classInfo.className}Dao
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<${classInfo.className}> findAllList(Map<String,Object> params) {
|
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}>(${classInfo.className}.class));
|
List<${classInfo.className}> list = jdbcTemplate.query("select * from ${classInfo.originTableName}", new Object[]{}, new BeanPropertyRowMapper<${classInfo.className}>(${classInfo.className}.class));
|
||||||
if(list!=null && !list.isEmpty() ){
|
if(list!=null && !list.isEmpty() ){
|
||||||
return list;
|
return list;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.entity;</#if>
|
||||||
|
|
||||||
|
<#if isAutoImport?exists && isAutoImport==true>
|
||||||
|
<#if isLombok?exists && isLombok==true>import lombok.Data;</#if>
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
<#if isSwagger?exists && isSwagger==true>
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;</#if>
|
||||||
|
</#if>
|
||||||
|
/**
|
||||||
|
* @description ${classInfo.classComment}
|
||||||
|
* @author ${authorName}
|
||||||
|
* @date ${.now?string('yyyy-MM-dd')}
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||||
|
<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||||
|
@ApiModel("${classInfo.classComment}")</#if>
|
||||||
|
public class ${classInfo.className} implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@ApiModelProperty("id")
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
|
<#list classInfo.fieldList as fieldItem >
|
||||||
|
<#if isComment?exists && isComment==true>/**
|
||||||
|
* ${fieldItem.fieldComment}
|
||||||
|
*/</#if><#if isSwagger?exists && isSwagger==true>
|
||||||
|
@ApiModelProperty("${fieldItem.fieldComment}")</#if>
|
||||||
|
<#if isComment?exists && isComment==true>@Column(name="${fieldItem.columnName}")</#if>
|
||||||
|
private ${fieldItem.fieldClass} ${fieldItem.fieldName};
|
||||||
|
|
||||||
|
</#list>
|
||||||
|
public ${classInfo.className}() {
|
||||||
|
}
|
||||||
|
</#if>
|
||||||
|
|
||||||
|
<#if isLombok?exists && isLombok==false>
|
||||||
|
public ${fieldItem.fieldClass} get${fieldItem.fieldName?cap_first}() {
|
||||||
|
return ${fieldItem.fieldName};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set${fieldItem.fieldName?cap_first}(${fieldItem.fieldClass} ${fieldItem.fieldName}) {
|
||||||
|
this.${fieldItem.fieldName} = ${fieldItem.fieldName};
|
||||||
|
}
|
||||||
|
</#if>
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.controller;</#if>
|
||||||
|
<#if isAutoImport?exists && isAutoImport==true>
|
||||||
|
import ${packageName}.entity.${classInfo.className};
|
||||||
|
import ${packageName}.repository.${classInfo.className}Repository;
|
||||||
|
import org.springframework.data.domain.Example;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.data.domain.ExampleMatcher;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
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;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
</#if>
|
||||||
|
/**
|
||||||
|
* @description ${classInfo.classComment}
|
||||||
|
* @author ${authorName}
|
||||||
|
* @date ${.now?string('yyyy-MM-dd')}
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "${classInfo.className?uncap_first}")
|
||||||
|
@CrossOrigin
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/${classInfo.className?uncap_first}")
|
||||||
|
public class ${classInfo.className}Controller {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ${classInfo.className}Repository ${classInfo.className?uncap_first}Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增或编辑
|
||||||
|
*/
|
||||||
|
@PostMapping("/save")
|
||||||
|
@ApiOperation(value = "save ${classInfo.className}", notes = "save ${classInfo.className}")
|
||||||
|
public Object save(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first}){
|
||||||
|
try {
|
||||||
|
return ReturnT.success(${classInfo.className?uncap_first}Repository.save(${classInfo.className?uncap_first}));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ReturnT.error("保存失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@PostMapping("/delete")
|
||||||
|
@ApiOperation(value = "delete ${classInfo.className}", notes = "delete ${classInfo.className}")
|
||||||
|
public Object delete(int id){
|
||||||
|
Optional<${classInfo.className}> ${classInfo.className?uncap_first}=${classInfo.className?uncap_first}Repository.findById(id);
|
||||||
|
if(${classInfo.className?uncap_first}.isPresent()){
|
||||||
|
${classInfo.className?uncap_first}Repository.deleteById(id);
|
||||||
|
return ${returnUtilSuccess}("删除成功");
|
||||||
|
}else{
|
||||||
|
return ${returnUtilFailure}("没有找到该对象");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
*/
|
||||||
|
@PostMapping("/find")
|
||||||
|
@ApiOperation(value = "find ${classInfo.className} by id", notes = "find ${classInfo.className} by 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 ${returnUtilSuccess}(${classInfo.className?uncap_first}.get());
|
||||||
|
}else{
|
||||||
|
return ${returnUtilFailure}("没有找到该对象");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperation(value = "list ${classInfo.className}", notes = "list ${classInfo.className}")
|
||||||
|
public Object list(@RequestBody ${classInfo.className} ${classInfo.className?uncap_first},
|
||||||
|
@RequestParam(required = false, defaultValue = "0") int pageNumber,
|
||||||
|
@RequestParam(required = false, defaultValue = "10") int pageSize) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
//创建匹配器,需要查询条件请修改此处代码
|
||||||
|
ExampleMatcher matcher = ExampleMatcher.matchingAll();
|
||||||
|
|
||||||
|
//创建实例
|
||||||
|
Example<${classInfo.className}> example = Example.of(${classInfo.className?uncap_first}, matcher);
|
||||||
|
//分页构造
|
||||||
|
Pageable pageable = PageRequest.of(pageNumber,pageSize);
|
||||||
|
|
||||||
|
return ReturnT.success(${classInfo.className?uncap_first}Repository.findAll(example, pageable));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ReturnT.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.repository;</#if>
|
||||||
|
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
||||||
|
|
||||||
|
<#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.util.List;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
</#if>
|
||||||
|
/**
|
||||||
|
* @description ${classInfo.classComment}
|
||||||
|
* @author ${authorName}
|
||||||
|
* @date ${.now?string('yyyy-MM-dd')}
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface ${classInfo.className}Repository extends JpaRepository<${classInfo.className},Integer> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ import io.swagger.annotations.ApiModelProperty;</#if>
|
|||||||
*/
|
*/
|
||||||
@Entity
|
@Entity
|
||||||
<#if isLombok?exists && isLombok==true>@Data</#if>
|
<#if isLombok?exists && isLombok==true>@Data</#if>
|
||||||
<#if isComment?exists && isComment==true>@Table(name="${classInfo.tableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
<#if isComment?exists && isComment==true>@Table(name="${classInfo.originTableName}")</#if><#if isSwagger?exists && isSwagger==true>
|
||||||
@ApiModel("${classInfo.classComment}")</#if>
|
@ApiModel("${classInfo.classComment}")</#if>
|
||||||
public class ${classInfo.className} implements Serializable {
|
public class ${classInfo.className} implements Serializable {
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
</#if>
|
</#if>
|
||||||
/**
|
/**
|
||||||
* @description ${classInfo.classComment}
|
* @description ${classInfo.classComment}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.mapper;</#if>
|
<#if isWithPackage?exists && isWithPackage==true>package ${packageName}.repository;</#if>
|
||||||
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
<#if isAutoImport?exists && isAutoImport==true>import ${packageName}.entity.${classInfo.className};
|
||||||
|
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class ${classInfo.className}Controller {
|
|||||||
* @date ${.now?string('yyyy/MM/dd')}
|
* @date ${.now?string('yyyy/MM/dd')}
|
||||||
**/
|
**/
|
||||||
@RequestMapping("/delete")
|
@RequestMapping("/delete")
|
||||||
public ReturnT<String> delete(int id){
|
public Object delete(int id){
|
||||||
return ${classInfo.className?uncap_first}Service.delete(id);
|
return ${classInfo.className?uncap_first}Service.delete(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class ${classInfo.className}Controller {
|
|||||||
* @date ${.now?string('yyyy/MM/dd')}
|
* @date ${.now?string('yyyy/MM/dd')}
|
||||||
**/
|
**/
|
||||||
@RequestMapping("/update")
|
@RequestMapping("/update")
|
||||||
public ReturnT<String> update(${classInfo.className} ${classInfo.className?uncap_first}){
|
public Object update(${classInfo.className} ${classInfo.className?uncap_first}){
|
||||||
return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first});
|
return ${classInfo.className?uncap_first}Service.update(${classInfo.className?uncap_first});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="${packageName}.dao.${classInfo.className}Dao">
|
<mapper namespace="${packageName}.dao.${classInfo.className}Mapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="${packageName}.entity.${classInfo.className}Entity" >
|
<resultMap id="BaseResultMap" type="${packageName}.entity.${classInfo.className}" >
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
<result column="${fieldItem.columnName}" property="${fieldItem.fieldName}" />
|
||||||
@@ -19,13 +19,13 @@
|
|||||||
</#if>
|
</#if>
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
<insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="${packageName}.entity.${classInfo.className}">
|
||||||
INSERT INTO ${classInfo.tableName}
|
INSERT INTO ${classInfo.originTableName}
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
<#if classInfo.fieldList?exists && classInfo.fieldList?size gt 0>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<#if fieldItem.columnName != "id" >
|
<#if fieldItem.columnName != "id" >
|
||||||
<if test="null != ${fieldItem.fieldName} and '' != ${fieldItem.fieldName}">
|
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">
|
||||||
${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
|
${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
|
||||||
${r"</if>"}
|
${r"</if>"}
|
||||||
</#if>
|
</#if>
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
NOW()<#if fieldItem_has_next>,</#if>
|
NOW()<#if fieldItem_has_next>,</#if>
|
||||||
${r"</if>"}
|
${r"</if>"}
|
||||||
<#else>-->
|
<#else>-->
|
||||||
<if test="null != ${fieldItem.fieldName} and '' != ${fieldItem.fieldName}">
|
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">
|
||||||
${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
|
||||||
${r"</if>"}
|
${r"</if>"}
|
||||||
<#--</#if>-->
|
<#--</#if>-->
|
||||||
@@ -52,16 +52,16 @@
|
|||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<delete id="delete" >
|
<delete id="delete" >
|
||||||
DELETE FROM ${classInfo.tableName}
|
DELETE FROM ${classInfo.originTableName}
|
||||||
WHERE id = ${r"#{id}"}
|
WHERE id = ${r"#{id}"}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<update id="update" parameterType="${packageName}.entity.${classInfo.className}Entity">
|
<update id="update" parameterType="${packageName}.entity.${classInfo.className}">
|
||||||
UPDATE ${classInfo.tableName}
|
UPDATE ${classInfo.originTableName}
|
||||||
<set>
|
<set>
|
||||||
<#list classInfo.fieldList as fieldItem >
|
<#list classInfo.fieldList as fieldItem >
|
||||||
<#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
<#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
|
||||||
<if test="null != ${fieldItem.fieldName} and '' != ${fieldItem.fieldName}">${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
|
<if test="null != ${fieldItem.fieldName} <#if fieldItem.fieldClass ="String">and '' != ${fieldItem.fieldName}</#if>">${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
|
||||||
</#if>
|
</#if>
|
||||||
</#list>
|
</#list>
|
||||||
</set>
|
</set>
|
||||||
@@ -71,19 +71,19 @@
|
|||||||
|
|
||||||
<select id="load" resultMap="BaseResultMap">
|
<select id="load" resultMap="BaseResultMap">
|
||||||
SELECT <include refid="Base_Column_List" />
|
SELECT <include refid="Base_Column_List" />
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.originTableName}
|
||||||
WHERE id = ${r"#{id}"}
|
WHERE id = ${r"#{id}"}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="pageList" resultMap="BaseResultMap">
|
<select id="pageList" resultMap="BaseResultMap">
|
||||||
SELECT <include refid="Base_Column_List" />
|
SELECT <include refid="Base_Column_List" />
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.originTableName}
|
||||||
LIMIT ${r"#{offset}"}, ${r"#{pageSize}"}
|
LIMIT ${r"#{offset}"}, ${r"#{pageSize}"}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="pageListCount" resultType="java.lang.Integer">
|
<select id="pageListCount" resultType="java.lang.Integer">
|
||||||
SELECT count(1)
|
SELECT count(1)
|
||||||
FROM ${classInfo.tableName}
|
FROM ${classInfo.originTableName}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -140,6 +140,7 @@
|
|||||||
vm.formData.options.returnUtilSuccess="${(value.returnUtilSuccess)!!}";
|
vm.formData.options.returnUtilSuccess="${(value.returnUtilSuccess)!!}";
|
||||||
vm.formData.options.returnUtilFailure="${(value.returnUtilFailure)!!}";
|
vm.formData.options.returnUtilFailure="${(value.returnUtilFailure)!!}";
|
||||||
vm.outputStr="${(value.outputStr)!!}";
|
vm.outputStr="${(value.outputStr)!!}";
|
||||||
|
loadAllCookie()
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
10
pom.xml
10
pom.xml
@@ -11,7 +11,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.2.7.RELEASE</version>
|
<version>2.6.3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.60</version>
|
<version>1.2.79</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 支持 @ConfigurationProperties 注解 -->
|
<!-- 支持 @ConfigurationProperties 注解 -->
|
||||||
@@ -78,7 +78,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.12</version>
|
<version>1.18.22</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- freemarker -->
|
<!-- freemarker -->
|
||||||
@@ -98,13 +98,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.9</version>
|
<version>3.12.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.8.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
Reference in New Issue
Block a user