commit init
This commit is contained in:
70
ym-generator/pom.xml
Normal file
70
ym-generator/pom.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ym-pass</artifactId>
|
||||
<groupId>com.cnbm</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ym-generator</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.cnbm</groupId>
|
||||
<artifactId>ym-common</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cnbm</groupId>
|
||||
<artifactId>ym-admin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-generator</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.freemarker</groupId>
|
||||
<artifactId>freemarker</artifactId>
|
||||
<version>2.3.29</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-freemarker</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
<!-- 模板引擎 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-engine-core</artifactId>
|
||||
<version>2.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.cnbm.generator.build;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
|
||||
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
||||
import com.baomidou.mybatisplus.generator.function.ConverterFileName;
|
||||
import com.cnbm.generator.config.DataConfig;
|
||||
import com.cnbm.generator.engine.EnhanceVelocityTemplateEngine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
import static com.baomidou.mybatisplus.generator.config.ConstVal.MODULE_NAME;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/14 8:47 AM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class CodeGenerator {
|
||||
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
mybatisPlusGenerator(new String[]{"sys_user"});
|
||||
}
|
||||
|
||||
public static void mybatisPlusGenerator(String[] include){
|
||||
File file = new File("");
|
||||
String path = file.getAbsolutePath();
|
||||
Map<String, String> customFile = new HashMap<>();
|
||||
customFile.put("DTO","/templates/DTO.java.vm");
|
||||
customFile.put("Excel","/templates/Excel.java.vm");
|
||||
|
||||
// customFile.put("Excel","/templates/excel.java.vm");
|
||||
// new TemplateConfig.Builder().serviceImpl("/templates/serviceImpl.java");
|
||||
FastAutoGenerator.create(DataConfig.url,DataConfig.username,DataConfig.password)
|
||||
.globalConfig(builder -> {
|
||||
builder.author("why")
|
||||
.enableSwagger()
|
||||
.fileOverride()
|
||||
.outputDir(path+"/src/main/java");
|
||||
})
|
||||
.packageConfig(builder -> {
|
||||
//设置父包名
|
||||
builder.parent("com.cnbm")
|
||||
.moduleName("generator")
|
||||
.service("service")
|
||||
.serviceImpl("service.impl")
|
||||
.entity("entity")
|
||||
.mapper("mapper")
|
||||
.controller("controller")
|
||||
.xml("mapper");
|
||||
})
|
||||
.strategyConfig(builder -> {
|
||||
//设置需要生成的表名
|
||||
builder.addInclude(include)
|
||||
//设置过滤表前缀
|
||||
.addTablePrefix("sys_")
|
||||
// .entityBuilder().formatFileName("%sEntity")
|
||||
// .mapperBuilder().formatMapperFileName("%sMapper").formatXmlFileName("%sMapper")
|
||||
// .controllerBuilder().formatFileName("%sController").enableRestStyle()
|
||||
// .serviceBuilder().formatServiceFileName("%sService").formatServiceImplFileName("%sServiceImpl")
|
||||
;
|
||||
})
|
||||
.injectionConfig(consumer -> {
|
||||
|
||||
consumer.customFile(customFile);
|
||||
})
|
||||
.templateEngine(new EnhanceVelocityTemplateEngine())
|
||||
// .templateEngine(new VelocityTemplateEngine(){
|
||||
// @Override
|
||||
// protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||
// //存放取出的实体名称,用于生成路由
|
||||
// List<String> entityNames = new ArrayList<>();
|
||||
//
|
||||
// if (!entityNames.contains(tableInfo.getEntityName())) {
|
||||
// entityNames.add(tableInfo.getEntityName());
|
||||
// }
|
||||
//
|
||||
// customFile.forEach((key, value) -> {
|
||||
// String fileName = String.format(path + "/src/main/resources/static/" + tableInfo.getEntityName() + File.separator + tableInfo.getEntityName() + "%s", key);
|
||||
// this.outputFile(new File(fileName), objectMap, "");
|
||||
// });
|
||||
//
|
||||
// // 生成路由部分
|
||||
// Map<String, Object> routers = new HashMap<>();
|
||||
// routers.put("author", "why");
|
||||
// routers.put("date", new Date());
|
||||
// routers.put("entities", entityNames);
|
||||
//
|
||||
// // 使用 freemarker 模板引擎,路由页面路径
|
||||
// String templateRoutesPath = "/templates/DTO.java.vm";
|
||||
//
|
||||
// // 生成的路由页面路径
|
||||
// File templateRoutesOutFile = new File(path + "/src/main/java/com/cnbm/generator/engine/"+tableInfo.getEntityName() +"DTO.java");
|
||||
// try {
|
||||
// this.writer(routers, templateRoutesPath, templateRoutesOutFile);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
|
||||
// .templateEngine(new FreemarkerTemplateEngine(){
|
||||
// @Override
|
||||
// protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||
// //存放取出的实体名称,用于生成路由
|
||||
// List<String> entityNames = new ArrayList<>();
|
||||
//
|
||||
// if (!entityNames.contains(tableInfo.getEntityName())) {
|
||||
// entityNames.add(tableInfo.getEntityName());
|
||||
// }
|
||||
//
|
||||
// customFile.forEach((key, value) -> {
|
||||
// String fileName = String.format(path + "/src/main/resources/static/" + tableInfo.getEntityName() + File.separator + tableInfo.getEntityName() + "%s", key);
|
||||
// this.outputFile(new File(fileName), objectMap, "");
|
||||
// });
|
||||
//
|
||||
// // 生成路由部分
|
||||
// Map<String, Object> routers = new HashMap<>();
|
||||
// routers.put("author", "why");
|
||||
// routers.put("date", new Date());
|
||||
// routers.put("entities", entityNames);
|
||||
//
|
||||
// // 使用 freemarker 模板引擎,路由页面路径
|
||||
// String templateRoutesPath = "/templates/excel.java.ftl";
|
||||
//
|
||||
// // 生成的路由页面路径
|
||||
// File templateRoutesOutFile = new File(path + "/src/main/java/com/cnbm/generator/engine/excel.java");
|
||||
// try {
|
||||
// this.writer(routers, templateRoutesPath, templateRoutesOutFile);
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// })
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.cnbm.generator.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/14 1:28 PM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class DataConfig {
|
||||
public static final String url = "jdbc:mysql://mysql.picaiba.com:30307/ym_pass?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true";
|
||||
public static final String username = "root";
|
||||
public static final String password = "1qaz@WSX3edc$RFV";
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.cnbm.generator.engine;
|
||||
|
||||
import com.baomidou.mybatisplus.generator.config.OutputFile;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author weihongyang
|
||||
* @Date 2022/6/17 10:27 AM
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class EnhanceVelocityTemplateEngine extends VelocityTemplateEngine {
|
||||
@Override
|
||||
protected void outputCustomFile(@NotNull Map<String, String> customFile, @NotNull TableInfo tableInfo, @NotNull Map<String, Object> objectMap) {
|
||||
String entityName = tableInfo.getEntityName();
|
||||
System.out.println(entityName);
|
||||
// String otherPath = this.getPathInfo(OutputFile.other);
|
||||
File file = new File("");
|
||||
String path = file.getAbsolutePath();
|
||||
customFile.forEach((key, value) -> {
|
||||
String fileName = "";
|
||||
if ("DTO".equals(key)) {
|
||||
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "dto" + File.separator + entityName + "%s" + ".java"), key);
|
||||
}
|
||||
if ("Excel".equals(key)) {
|
||||
fileName = String.format((path+ File.separator +"src/main/java/com/cnbm/generator"+ File.separator + "excel" + File.separator + entityName + "%s" + ".java"), key);
|
||||
}
|
||||
this.outputFile(new File(fileName), objectMap, value);
|
||||
});
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void writer(Map<String, Object> objectMap, String templatePath, File outputFile) throws Exception {
|
||||
// // 获取table
|
||||
// TableInfo tableInfo = (TableInfo) objectMap.get("table");
|
||||
// // 取出Service接口的名字,进行首字母小写处理
|
||||
// String serviceNameFirstWord = tableInfo.getServiceName().substring(0,1).toLowerCase();
|
||||
// String serviceNameFirstWordToLower = serviceNameFirstWord + tableInfo.getServiceName().substring(1);
|
||||
// objectMap.put("serviceNameFirstWordToLower", serviceNameFirstWordToLower);
|
||||
//
|
||||
// // 取出mapper接口的名字,进行首字母小写处理
|
||||
// String mapperNameFirstWord = tableInfo.getMapperName().substring(0, 1).toLowerCase();
|
||||
// String mapperNameFirstWordToLower = mapperNameFirstWord + tableInfo.getMapperName().substring(1);
|
||||
// objectMap.put("mapperNameFirstWordToLower", mapperNameFirstWordToLower);
|
||||
//
|
||||
// // 对Form、VO文件的处理
|
||||
//// new FormHandler().handler(objectMap);
|
||||
// super.writer(objectMap, templatePath, outputFile);
|
||||
// }
|
||||
|
||||
}
|
||||
32
ym-generator/src/main/resources/templates/DTO.java.vm
Normal file
32
ym-generator/src/main/resources/templates/DTO.java.vm
Normal file
@@ -0,0 +1,32 @@
|
||||
package ${package.Parent}.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
|
||||
/**
|
||||
* ${table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
@ApiModel(value = "${table.comment}DTO对象")
|
||||
public class ${entity}DTO implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
@ApiModelProperty(value = "${field.comment}")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
}
|
||||
24
ym-generator/src/main/resources/templates/Excel.java.vm
Normal file
24
ym-generator/src/main/resources/templates/Excel.java.vm
Normal file
@@ -0,0 +1,24 @@
|
||||
package ${package.Parent}.excel;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
#if(${hasBigDecimal})
|
||||
import java.math.BigDecimal;
|
||||
#end
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* ${table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
public class ${entity}Excel {
|
||||
#foreach($field in ${table.fields})
|
||||
@Excel(name = "$!field.comment")
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
|
||||
}
|
||||
116
ym-generator/src/main/resources/templates/controller.java.vm
Normal file
116
ym-generator/src/main/resources/templates/controller.java.vm
Normal file
@@ -0,0 +1,116 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import com.cnbm.admin.annotation.LogOperation;
|
||||
import com.cnbm.common.constant.Constant;
|
||||
import com.cnbm.common.page.PageData;
|
||||
import com.cnbm.common.utils.ExcelUtils;
|
||||
import com.cnbm.common.utils.Result;
|
||||
import com.cnbm.common.validator.AssertUtils;
|
||||
import com.cnbm.common.validator.ValidatorUtils;
|
||||
import com.cnbm.common.validator.group.AddGroup;
|
||||
import com.cnbm.common.validator.group.DefaultGroup;
|
||||
import com.cnbm.common.validator.group.UpdateGroup;
|
||||
import ${package.Parent}.dto.${entity}DTO;
|
||||
import ${package.Parent}.excel.${entity}Excel;
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* ${table.comment} 前端控制器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("#if(${package.ModuleName})/${package.ModuleName}#end/#if(${controllerMappingHyphenStyle})${controllerMappingHyphen}#else${table.entityPath}#end")
|
||||
@Api(tags="${table.comment}")
|
||||
public class ${table.controllerName} {
|
||||
@Autowired
|
||||
private ${table.serviceName} ${table.entityPath}Service;
|
||||
|
||||
@GetMapping("page")
|
||||
@ApiOperation("分页")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType="int") ,
|
||||
@ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query",required = true, dataType="int") ,
|
||||
@ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType="String") ,
|
||||
@ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType="String")
|
||||
})
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:page')")
|
||||
public Result<PageData<${entity}DTO>> page(@ApiIgnore @RequestParam Map<String, Object> params){
|
||||
PageData<${entity}DTO> page = ${table.entityPath}Service.page(params);
|
||||
|
||||
return new Result<PageData<${entity}DTO>>().ok(page);
|
||||
}
|
||||
|
||||
@GetMapping("{id}")
|
||||
@ApiOperation("信息")
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:info')")
|
||||
public Result<${entity}DTO> get(@PathVariable("id") Long id){
|
||||
${entity}DTO data = ${table.entityPath}Service.get(id);
|
||||
|
||||
return new Result<${entity}DTO>().ok(data);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
@ApiOperation("保存")
|
||||
@LogOperation("保存")
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:save')")
|
||||
public Result save(@RequestBody ${entity}DTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
|
||||
|
||||
${table.entityPath}Service.save(dto);
|
||||
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
@ApiOperation("修改")
|
||||
@LogOperation("修改")
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:update')")
|
||||
public Result update(@RequestBody ${entity}DTO dto){
|
||||
//效验数据
|
||||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class);
|
||||
|
||||
${table.entityPath}Service.update(dto);
|
||||
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除")
|
||||
@LogOperation("删除")
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:delete')")
|
||||
public Result delete(@RequestBody Long[] ids){
|
||||
//效验数据
|
||||
AssertUtils.isArrayEmpty(ids, "id");
|
||||
|
||||
${table.entityPath}Service.delete(ids);
|
||||
|
||||
return new Result();
|
||||
}
|
||||
|
||||
@GetMapping("export")
|
||||
@ApiOperation("导出")
|
||||
@LogOperation("导出")
|
||||
@PreAuthorize("@ex.hasAuthority('${package.ModuleName}:${table.entityPath}:export')")
|
||||
public void export(@ApiIgnore @RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception {
|
||||
List<${entity}DTO> list = ${table.entityPath}Service.list(params);
|
||||
|
||||
ExcelUtils.exportExcelToTarget(response, null, list, ${entity}Excel.class);
|
||||
}
|
||||
|
||||
}
|
||||
120
ym-generator/src/main/resources/templates/entity.java.vm
Normal file
120
ym-generator/src/main/resources/templates/entity.java.vm
Normal file
@@ -0,0 +1,120 @@
|
||||
package ${package.Entity};
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${swagger})
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* $!{table.comment}
|
||||
* </p>
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Data
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${schemaName}${table.name}")
|
||||
#end
|
||||
#if(${swagger})
|
||||
@ApiModel(value = "${entity}对象", description = "$!{table.comment}")
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
public class ${entity} extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity} implements Serializable {
|
||||
#else
|
||||
public class ${entity} {
|
||||
#end
|
||||
#if(${entitySerialVersionUID})
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
#end
|
||||
## ---------- BEGIN 字段循环遍历 ----------
|
||||
#foreach($field in ${table.fields})
|
||||
|
||||
#if(${field.keyFlag})
|
||||
#set($keyPropertyName=${field.propertyName})
|
||||
#end
|
||||
#if("$!field.comment" != "")
|
||||
#if(${swagger})
|
||||
@ApiModelProperty("${field.comment}")
|
||||
#else
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#end
|
||||
#end
|
||||
#if(${field.keyFlag})
|
||||
## 主键
|
||||
#if(${field.keyIdentityFlag})
|
||||
@TableId(value = "${field.annotationColumnName}", type = IdType.AUTO)
|
||||
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
|
||||
@TableId(value = "${field.annotationColumnName}", type = IdType.${idType})
|
||||
#elseif(${field.convert})
|
||||
@TableId("${field.annotationColumnName}")
|
||||
#end
|
||||
## 普通字段
|
||||
#elseif(${field.fill})
|
||||
## ----- 存在字段填充设置 -----
|
||||
#if(${field.convert})
|
||||
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
|
||||
#else
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
#end
|
||||
#elseif(${field.convert})
|
||||
@TableField("${field.annotationColumnName}")
|
||||
#end
|
||||
## 乐观锁注解
|
||||
#if(${field.versionField})
|
||||
@Version
|
||||
#end
|
||||
## 逻辑删除注解
|
||||
#if(${field.logicDeleteField})
|
||||
@TableLogic
|
||||
#end
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
|
||||
## --end of #if(!${entityLombokModel})--
|
||||
|
||||
#if(${entityColumnConstant})
|
||||
#foreach($field in ${table.fields})
|
||||
public static final String ${field.name.toUpperCase()} = "${field.name}";
|
||||
|
||||
#end
|
||||
#end
|
||||
#if(${activeRecord})
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
#if(${keyPropertyName})
|
||||
return this.${keyPropertyName};
|
||||
#else
|
||||
return null;
|
||||
#end
|
||||
}
|
||||
|
||||
#end
|
||||
}
|
||||
16
ym-generator/src/main/resources/templates/mapper.java.vm
Normal file
16
ym-generator/src/main/resources/templates/mapper.java.vm
Normal file
@@ -0,0 +1,16 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import com.cnbm.common.dao.BaseDao;
|
||||
import ${package.Entity}.${table.entityName};
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* ${table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper
|
||||
public interface ${table.mapperName} extends BaseDao<${entity}> {
|
||||
|
||||
}
|
||||
39
ym-generator/src/main/resources/templates/mapper.xml.vm
Normal file
39
ym-generator/src/main/resources/templates/mapper.xml.vm
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="${package.Mapper}.${table.mapperName}">
|
||||
|
||||
#if(${enableCache})
|
||||
<!-- 开启二级缓存 -->
|
||||
<cache type="${cacheClassName}"/>
|
||||
|
||||
#end
|
||||
#if(${baseResultMap})
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="${package.Entity}.${entity}">
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.keyFlag})##生成主键排在第一位
|
||||
<id column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
#foreach($field in ${table.commonFields})##生成公共字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#foreach($field in ${table.fields})
|
||||
#if(!${field.keyFlag})##生成普通字段
|
||||
<result column="${field.name}" property="${field.propertyName}" />
|
||||
#end
|
||||
#end
|
||||
</resultMap>
|
||||
|
||||
#end
|
||||
#if(${baseColumnList})
|
||||
<!-- 通用查询结果列 -->
|
||||
<sql id="Base_Column_List">
|
||||
#foreach($field in ${table.commonFields})
|
||||
${field.columnName},
|
||||
#end
|
||||
${table.fieldNames}
|
||||
</sql>
|
||||
|
||||
#end
|
||||
</mapper>
|
||||
15
ym-generator/src/main/resources/templates/service.java.vm
Normal file
15
ym-generator/src/main/resources/templates/service.java.vm
Normal file
@@ -0,0 +1,15 @@
|
||||
package ${package.Service};
|
||||
|
||||
import com.cnbm.common.service.CrudService;
|
||||
import ${package.Parent}.dto.${table.entityName}DTO;
|
||||
import ${package.Entity}.${table.entityName};
|
||||
|
||||
/**
|
||||
* ${table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${table.serviceName} extends CrudService<${table.entityName}, ${table.entityName}DTO> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cnbm.common.service.impl.CrudServiceImpl;
|
||||
import ${package.Parent}.dto.${table.entityName}DTO;
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Entity}.${table.entityName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ${table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
public class ${table.serviceImplName} extends CrudServiceImpl<${table.mapperName}, ${table.entityName}, ${entity}DTO> implements ${table.serviceName} {
|
||||
|
||||
@Override
|
||||
public QueryWrapper<${entity}> getWrapper(Map<String, Object> params){
|
||||
String id = (String)params.get("id");
|
||||
|
||||
QueryWrapper<${entity}> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq(StringUtils.isNotBlank(id), "id", id);
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user