mirror of https://gitee.com/makejava/EasyCode.git
优化模板信息并添加配置版本号
This commit is contained in:
parent
550494a1e0
commit
4223249a1e
|
@ -29,6 +29,9 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
|
||||||
@Transient
|
@Transient
|
||||||
public static final String DEFAULT_NAME = "Default";
|
public static final String DEFAULT_NAME = "Default";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本号
|
||||||
|
*/
|
||||||
private String version;
|
private String version;
|
||||||
/**
|
/**
|
||||||
* 当前类型映射组名
|
* 当前类型映射组名
|
||||||
|
@ -92,6 +95,8 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
|
||||||
* 初始化默认设置
|
* 初始化默认设置
|
||||||
*/
|
*/
|
||||||
private void initDefault() {
|
private void initDefault() {
|
||||||
|
// 版本号
|
||||||
|
this.version = "1.1.0";
|
||||||
// 默认编码
|
// 默认编码
|
||||||
this.encode = "UTF-8";
|
this.encode = "UTF-8";
|
||||||
// 作者名称
|
// 作者名称
|
||||||
|
@ -105,7 +110,7 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
|
||||||
if (this.templateGroupMap == null) {
|
if (this.templateGroupMap == null) {
|
||||||
this.templateGroupMap = new LinkedHashMap<>();
|
this.templateGroupMap = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
for (String groupName : new String[]{DEFAULT_NAME, "Mybatis"}) {
|
for (String groupName : new String[]{DEFAULT_NAME, "MybatisPlus"}) {
|
||||||
this.templateGroupMap.put(groupName, loadTemplateGroup(groupName));
|
this.templateGroupMap.put(groupName, loadTemplateGroup(groupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +150,7 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
|
||||||
if (this.globalConfigGroupMap == null) {
|
if (this.globalConfigGroupMap == null) {
|
||||||
this.globalConfigGroupMap = new LinkedHashMap<>();
|
this.globalConfigGroupMap = new LinkedHashMap<>();
|
||||||
}
|
}
|
||||||
for (String groupName : new String[]{DEFAULT_NAME, "Mybatis"}) {
|
for (String groupName : new String[]{DEFAULT_NAME}) {
|
||||||
this.globalConfigGroupMap.put(groupName, loadGlobalConfigGroup(groupName));
|
this.globalConfigGroupMap.put(groupName, loadGlobalConfigGroup(groupName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,6 +245,16 @@ public class ConfigInfo implements PersistentStateComponent<ConfigInfo> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadState(@NotNull ConfigInfo configInfo) {
|
public void loadState(@NotNull ConfigInfo configInfo) {
|
||||||
|
// 备份初始配置
|
||||||
|
Map<String, TemplateGroup> templateGroupMap = this.getTemplateGroupMap();
|
||||||
|
// 覆盖初始配置
|
||||||
XmlSerializerUtil.copyBean(configInfo, this);
|
XmlSerializerUtil.copyBean(configInfo, this);
|
||||||
|
// 合并配置
|
||||||
|
templateGroupMap.forEach((name, templateGroup) -> {
|
||||||
|
if (this.getTemplateGroupMap().containsKey(name)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.getTemplateGroupMap().put(name, templateGroup);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,23 +5,23 @@
|
||||||
*#
|
*#
|
||||||
##定义区域(Velocity宏定义)
|
##定义区域(Velocity宏定义)
|
||||||
|
|
||||||
##定义设置表名后缀的宏定义,调用方式:$setTableSuffix("Test")
|
##定义设置表名后缀的宏定义,调用方式:#setTableSuffix("Test")
|
||||||
#macro(setTableSuffix $suffix)
|
#macro(setTableSuffix $suffix)
|
||||||
#set($tableName = $!tool.append($tableInfo.name, $suffix))
|
#set($tableName = $!tool.append($tableInfo.name, $suffix))
|
||||||
#end
|
#end
|
||||||
|
|
||||||
##定义设置包名后缀的宏定义,调用方式:$setPackageSuffix("Test")
|
##定义设置包名后缀的宏定义,调用方式:#setPackageSuffix("Test")
|
||||||
#macro(setPackageSuffix $suffix)
|
#macro(setPackageSuffix $suffix)
|
||||||
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}$suffix;
|
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}$suffix;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
##定义直接保存路径与文件名简化的宏定义,调用方式:$save("D:/", "Test.java")
|
##定义直接保存路径与文件名简化的宏定义,调用方式:#save("/entity", ".java")
|
||||||
#macro(save $path $fileName)
|
#macro(save $path $fileName)
|
||||||
$!callback.setSavePath($path)
|
$!callback.setSavePath($tool.append($tableInfo.savePath, $path))
|
||||||
$!callback.setFileName($fileName)
|
$!callback.setFileName($tool.append($tableInfo.name, $fileName))
|
||||||
#end
|
#end
|
||||||
|
|
||||||
##定义表注释的宏定义,调用方式:$tableComment("注释信息")
|
##定义表注释的宏定义,调用方式:#tableComment("注释信息")
|
||||||
#macro(tableComment $desc)
|
#macro(tableComment $desc)
|
||||||
/**
|
/**
|
||||||
* $!{tableInfo.comment}($!{tableInfo.name})$desc
|
* $!{tableInfo.comment}($!{tableInfo.name})$desc
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
*/
|
*/
|
||||||
#end
|
#end
|
||||||
|
|
||||||
##定义GET,SET方法的宏定义
|
##定义GET,SET方法的宏定义,调用方式:#getSetMethod($column)
|
||||||
#macro(getSetMethod $column)
|
#macro(getSetMethod $column)
|
||||||
|
|
||||||
public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {
|
public $!{tool.getClsNameByFullName($column.type)} get$!{tool.firstUpperCase($column.name)}() {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
##定义初始变量
|
|
||||||
#set($tableName = $tool.append($tableInfo.name, "Controller"))
|
|
||||||
##设置回调
|
|
||||||
$!callback.setFileName($tool.append($tableName, ".java"))
|
|
||||||
$!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
|
|
||||||
|
|
||||||
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{tableInfo.comment}($!{tableInfo.name})表控制层
|
|
||||||
*
|
|
||||||
* @author $!author
|
|
||||||
* @since $!time.currTime()
|
|
||||||
*/
|
|
||||||
public class $!{tableName} {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
##导入宏定义
|
|
||||||
$!define
|
|
||||||
##设置表后缀(宏定义)
|
|
||||||
$!setTableSuffix("Dao")
|
|
||||||
##设置回调
|
|
||||||
$!callback.setFileName($tool.append($tableName, ".java"))
|
|
||||||
$!callback.setSavePath($tool.append($tableInfo.savePath, "/dao"))
|
|
||||||
|
|
||||||
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}dao;
|
|
||||||
|
|
||||||
|
|
||||||
$!tableComment("表数据库访问层")
|
|
||||||
public interface $!{tableName} {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
##定义初始变量
|
|
||||||
#set($tableName = $tool.append($tableInfo.name, "Service"))
|
|
||||||
##设置回调
|
|
||||||
$!callback.setFileName($tool.append($tableName, ".java"))
|
|
||||||
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service"))
|
|
||||||
|
|
||||||
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{tableInfo.comment}($!{tableInfo.name})表服务接口
|
|
||||||
*
|
|
||||||
* @author $!author
|
|
||||||
* @since $!time.currTime()
|
|
||||||
*/
|
|
||||||
public interface $!{tableName} {
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
##定义初始变量
|
|
||||||
#set($tableName = $tool.append($tableInfo.name, "ServiceImpl"))
|
|
||||||
##设置回调
|
|
||||||
$!callback.setFileName($tool.append($tableName, ".java"))
|
|
||||||
$!callback.setSavePath($tool.append($tableInfo.savePath, "/service/impl"))
|
|
||||||
|
|
||||||
#if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}service.impl;
|
|
||||||
|
|
||||||
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* $!{tableInfo.comment}($!{tableInfo.name})表服务实现类
|
|
||||||
*
|
|
||||||
* @author $!author
|
|
||||||
* @since $!time.currTime()
|
|
||||||
*/
|
|
||||||
public class $!{tableName} implements $!{tableInfo.name}Service {
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
##导入宏定义
|
||||||
|
$!define
|
||||||
|
|
||||||
|
##设置表后缀(宏定义)
|
||||||
|
#setTableSuffix("Controller")
|
||||||
|
|
||||||
|
##保存文件(宏定义)
|
||||||
|
#save("/controller", "Controller.java")
|
||||||
|
|
||||||
|
##包路径(宏定义)
|
||||||
|
#setPackageSuffix("controller")
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import $!{tableInfo.savePackageName}.entity.$!tableInfo.name;
|
||||||
|
import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
|
||||||
|
|
||||||
|
##表注释(宏定义)
|
||||||
|
#tableComment("表控制层")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("$!tool.firstLowerCase($!{tableName})")
|
||||||
|
public class $!{tableName} {
|
||||||
|
@Resource
|
||||||
|
private $!{tableInfo.name}Service $!tool.firstLowerCase($!tableInfo.name)Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询所有数据
|
||||||
|
*
|
||||||
|
* @return 所有数据
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public String selectAll() {
|
||||||
|
return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.selectAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过主键查询单条数据
|
||||||
|
*
|
||||||
|
* @param id 主键
|
||||||
|
* @return 单条数据
|
||||||
|
*/
|
||||||
|
@GetMapping("{id}")
|
||||||
|
public String selectOne(@PathVariable Long id) {
|
||||||
|
return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.queryById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增数据
|
||||||
|
*
|
||||||
|
* @param entity 实体对象
|
||||||
|
* @return 新增结果
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
public String insert(@RequestBody $!tableInfo.name entity) {
|
||||||
|
return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.insert(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改数据
|
||||||
|
*
|
||||||
|
* @param entity 实体对象
|
||||||
|
* @return 修改结果
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
public String update(@RequestBody $!tableInfo.name entity) {
|
||||||
|
return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.update(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除数据
|
||||||
|
*
|
||||||
|
* @param idList 主键结合
|
||||||
|
* @return 删除结果
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
public String delete(@RequestParam("idList") List<Long> idList) {
|
||||||
|
return success(this.$!tool.firstLowerCase($!tableInfo.name)Service.deleteByIdList(idList));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功返回方法
|
||||||
|
*
|
||||||
|
* @param obj 对象
|
||||||
|
* @return JSON字符串
|
||||||
|
*/
|
||||||
|
public String success(Object obj) {
|
||||||
|
return JSON.toJSONString(obj);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
##导入宏定义
|
||||||
|
$!define
|
||||||
|
|
||||||
|
##设置表后缀(宏定义)
|
||||||
|
#setTableSuffix("Dao")
|
||||||
|
|
||||||
|
##保存文件(宏定义)
|
||||||
|
#save("/dao", "Dao.java")
|
||||||
|
|
||||||
|
##包路径(宏定义)
|
||||||
|
#setPackageSuffix("dao")
|
||||||
|
|
||||||
|
##表注释(宏定义)
|
||||||
|
#tableComment("表数据库访问层")
|
||||||
|
public interface $!{tableName} {
|
||||||
|
|
||||||
|
}
|
|
@ -2,15 +2,16 @@
|
||||||
$!define
|
$!define
|
||||||
|
|
||||||
##保存文件(宏定义)
|
##保存文件(宏定义)
|
||||||
$!save($tool.append($tableInfo.savePath, "/entity"), $tool.append($tableInfo.name, ".java"))
|
#save("/entity", ".java")
|
||||||
|
|
||||||
##包路径(宏定义)
|
##包路径(宏定义)
|
||||||
$!setPackageSuffix("entity")
|
#setPackageSuffix("entity")
|
||||||
|
|
||||||
##导入包(全局变量)
|
##导入包(全局变量)
|
||||||
$!import
|
$!import
|
||||||
|
|
||||||
$!tableComment("表实体类")
|
##表注释(宏定义)
|
||||||
|
#tableComment("表实体类")
|
||||||
public class $!{tableInfo.name} {
|
public class $!{tableInfo.name} {
|
||||||
#foreach($column in $tableInfo.fullColumn)
|
#foreach($column in $tableInfo.fullColumn)
|
||||||
#if(${column.comment})//${column.comment}#end
|
#if(${column.comment})//${column.comment}#end
|
||||||
|
@ -19,7 +20,7 @@ public class $!{tableInfo.name} {
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#foreach($column in $tableInfo.fullColumn)
|
#foreach($column in $tableInfo.fullColumn)
|
||||||
$!getSetMethod($column)
|
#getSetMethod($column)
|
||||||
#end
|
#end
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
##导入宏定义
|
||||||
|
$!define
|
||||||
|
|
||||||
|
##设置表后缀(宏定义)
|
||||||
|
#setTableSuffix("Service")
|
||||||
|
|
||||||
|
##保存文件(宏定义)
|
||||||
|
#save("/service", "Service.java")
|
||||||
|
|
||||||
|
##包路径(宏定义)
|
||||||
|
#setPackageSuffix("service")
|
||||||
|
|
||||||
|
##表注释(宏定义)
|
||||||
|
#tableComment("表服务接口")
|
||||||
|
public interface $!{tableName} {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
##导入宏定义
|
||||||
|
$!define
|
||||||
|
|
||||||
|
##设置表后缀(宏定义)
|
||||||
|
#setTableSuffix("ServiceImpl")
|
||||||
|
|
||||||
|
##保存文件(宏定义)
|
||||||
|
#save("/service/impl", "ServiceImpl.java")
|
||||||
|
|
||||||
|
##包路径(宏定义)
|
||||||
|
#setPackageSuffix("service.impl")
|
||||||
|
|
||||||
|
##表注释(宏定义)
|
||||||
|
#tableComment("表服务实现类")
|
||||||
|
public class $!{tableName} implements $!{tableInfo.name}Service {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue