feat: 添加后端代码生成器模板
This commit is contained in:
141
src/test/resources/templates/bo.java.vm
Normal file
141
src/test/resources/templates/bo.java.vm
Normal file
@@ -0,0 +1,141 @@
|
||||
package ${package.Parent}.model.bo;
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* $!{table.comment}
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
#if(${superEntityClass})
|
||||
public class ${entity}BO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity}BO extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity}BO implements Serializable {
|
||||
#else
|
||||
public class ${entity}BO {
|
||||
#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" != "")
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#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 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
81
src/test/resources/templates/controller.java.vm
Normal file
81
src/test/resources/templates/controller.java.vm
Normal file
@@ -0,0 +1,81 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ${package.Parent}.model.form.${entity}Form;
|
||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
||||
import ${package.Parent}.service.${table.serviceName};
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.youlai.common.result.PageResult;
|
||||
import com.youlai.common.result.Result;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
#if(${superControllerClassPackage})
|
||||
import ${superControllerClassPackage};
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment} 前端控制器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Tag(name = "${table.comment}接口")
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/${firstCharLowerCaseEntity}s")
|
||||
@RequiredArgsConstructor
|
||||
#if(${superControllerClass})
|
||||
public class ${table.controllerName} extends ${superControllerClass} {
|
||||
#else
|
||||
public class ${table.controllerName} {
|
||||
#end
|
||||
|
||||
private final ${table.serviceName} ${firstCharLowerCaseEntity}Service;
|
||||
|
||||
@Operation(summary = "$!{table.comment}分页列表")
|
||||
@GetMapping("/page")
|
||||
public PageResult<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams ) {
|
||||
IPage<${entity}PageVO> result = ${firstCharLowerCaseEntity}Service.listPaged${entity}s(queryParams);
|
||||
return PageResult.success(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "新增$!{table.comment}")
|
||||
@PostMapping
|
||||
public Result save${entity}(@RequestBody @Valid ${entity}Form formData ) {
|
||||
boolean result = ${firstCharLowerCaseEntity}Service.save${entity}(formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "$!{table.comment}表单数据")
|
||||
@GetMapping("/{id}/form")
|
||||
public Result<${entity}Form> get${entity}Form(
|
||||
@Parameter(description = "$!{table.comment}ID") @PathVariable Long id
|
||||
) {
|
||||
${entity}Form formData = ${firstCharLowerCaseEntity}Service.get${entity}FormData(id);
|
||||
return Result.success(formData);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改$!{table.comment}")
|
||||
@PutMapping(value = "/{id}")
|
||||
public Result update${entity}(@Parameter(description = "$!{table.comment}ID") @PathVariable Long id,
|
||||
@RequestBody @Validated ${entity}Form formData) {
|
||||
boolean result = ${firstCharLowerCaseEntity}Service.update${entity}(id, formData);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除$!{table.comment}")
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result delete${entity}s(
|
||||
@Parameter(description = "$!{table.comment}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
boolean result = ${firstCharLowerCaseEntity}Service.delete${entity}s(ids);
|
||||
return Result.judge(result);
|
||||
}
|
||||
}
|
||||
30
src/test/resources/templates/converter.java.vm
Normal file
30
src/test/resources/templates/converter.java.vm
Normal file
@@ -0,0 +1,30 @@
|
||||
package ${package.Parent}.converter;
|
||||
|
||||
import org.mapstruct.InheritInverseConfiguration;
|
||||
import org.mapstruct.Mapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import ${package.Parent}.model.dto.${entity}DTO;
|
||||
import ${package.Parent}.model.entity.${entity};
|
||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
||||
import ${package.Parent}.model.form.${entity}Form;
|
||||
import ${package.Parent}.model.bo.${entity}BO;
|
||||
|
||||
/**
|
||||
* $!{table.comment}转换器
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface ${entity}Converter{
|
||||
|
||||
${entity}PageVO toPageVo(${entity}BO bo);
|
||||
|
||||
Page<${entity}PageVO> toPageVo(Page<${entity}BO> bo);
|
||||
|
||||
${entity}Form toForm(${entity} entity);
|
||||
|
||||
@InheritInverseConfiguration(name = "toForm")
|
||||
${entity} toEntity(${entity}Form entity);
|
||||
}
|
||||
112
src/test/resources/templates/dto.java.vm
Normal file
112
src/test/resources/templates/dto.java.vm
Normal file
@@ -0,0 +1,112 @@
|
||||
package ${package.Parent}.model.dto;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
/**
|
||||
* $!{table.comment} DTO
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
@Schema( description = "$!{table.comment}传输层对象")
|
||||
#if(${superEntityClass})
|
||||
public class ${entity}DTO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity}DTO extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity}DTO implements Serializable {
|
||||
#else
|
||||
public class ${entity}DTO {
|
||||
#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" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
143
src/test/resources/templates/entity.java.vm
Normal file
143
src/test/resources/templates/entity.java.vm
Normal file
@@ -0,0 +1,143 @@
|
||||
package ${package.Entity};
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment}实体
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
#if(${table.convert})
|
||||
@TableName("${schemaName}${table.name}")
|
||||
#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" != "")
|
||||
/**
|
||||
* ${field.comment}
|
||||
*/
|
||||
#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 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
113
src/test/resources/templates/form.java.vm
Normal file
113
src/test/resources/templates/form.java.vm
Normal file
@@ -0,0 +1,113 @@
|
||||
package ${package.Parent}.model.form;
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment} 表单对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
@Schema(description = "$!{table.comment}表单对象")
|
||||
#if(${superEntityClass})
|
||||
public class ${entity}Form extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity}Form extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity}Form implements Serializable {
|
||||
#else
|
||||
public class ${entity}Form {
|
||||
#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" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
35
src/test/resources/templates/mapper.java.vm
Normal file
35
src/test/resources/templates/mapper.java.vm
Normal file
@@ -0,0 +1,35 @@
|
||||
package ${package.Mapper};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superMapperClassPackage};
|
||||
#if(${mapperAnnotationClass})
|
||||
import ${mapperAnnotationClass.name};
|
||||
#end
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import ${package.Parent}.model.bo.${entity}BO;
|
||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* $!{table.comment} Mapper 接口
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${mapperAnnotationClass})
|
||||
@${mapperAnnotationClass.simpleName}
|
||||
#end
|
||||
|
||||
@Mapper
|
||||
public interface ${table.mapperName} extends ${superMapperClass}<${entity}> {
|
||||
|
||||
/**
|
||||
* 获取用户分页列表
|
||||
*
|
||||
* @param page
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
*/
|
||||
Page<${entity}BO> listPaged${entity}s(Page<${entity}BO> page, ${entity}PageQuery queryParams);
|
||||
|
||||
}
|
||||
63
src/test/resources/templates/mapper.xml.vm
Normal file
63
src/test/resources/templates/mapper.xml.vm
Normal file
@@ -0,0 +1,63 @@
|
||||
<?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
|
||||
|
||||
<!-- ${table.comment}分页列表 -->
|
||||
<select id="listPaged${entity}s" resultType="${package.Parent}.model.bo.${entity}BO">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM
|
||||
${table.name}
|
||||
<where>
|
||||
is_deleted = 0
|
||||
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
|
||||
AND (
|
||||
name LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
)
|
||||
</if>
|
||||
<if test="queryParams.startTime != null">
|
||||
AND create_time >= #{queryParams.startTime}
|
||||
</if>
|
||||
<if test="queryParams.endTime != null">
|
||||
AND create_time <= #{queryParams.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
20
src/test/resources/templates/pageQuery.java.vm
Normal file
20
src/test/resources/templates/pageQuery.java.vm
Normal file
@@ -0,0 +1,20 @@
|
||||
package ${package.Parent}.model.query;
|
||||
|
||||
import com.youlai.common.base.BasePageQuery;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* $!{table.comment}分页查询对象
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Schema(description ="$!{table.comment}分页查询对象")
|
||||
@Data
|
||||
public class ${entity}PageQuery extends BasePageQuery {
|
||||
|
||||
@Schema(description="关键字")
|
||||
private String keywords;
|
||||
|
||||
}
|
||||
113
src/test/resources/templates/pageVo.java.vm
Normal file
113
src/test/resources/templates/pageVo.java.vm
Normal file
@@ -0,0 +1,113 @@
|
||||
package ${package.Parent}.model.vo;
|
||||
|
||||
#foreach($pkg in ${table.importPackages})
|
||||
import ${pkg};
|
||||
#end
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment} 分页VO
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
@Schema( description = "$!{table.comment}分页视图对象")
|
||||
#if(${superEntityClass})
|
||||
public class ${entity}PageVO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity}PageVO extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity}PageVO implements Serializable {
|
||||
#else
|
||||
public class ${entity}PageVO {
|
||||
#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" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
61
src/test/resources/templates/service.java.vm
Normal file
61
src/test/resources/templates/service.java.vm
Normal file
@@ -0,0 +1,61 @@
|
||||
package ${package.Service};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${superServiceClassPackage};
|
||||
import ${package.Parent}.model.form.${entity}Form;
|
||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
/**
|
||||
* $!{table.comment} 服务类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {
|
||||
|
||||
|
||||
/**
|
||||
*$!{table.comment}分页列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IPage<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams);
|
||||
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}表单数据
|
||||
*
|
||||
* @param id $!{table.comment}ID
|
||||
* @return
|
||||
*/
|
||||
${entity}Form get${entity}FormData(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 新增$!{table.comment}
|
||||
*
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean save${entity}(${entity}Form formData);
|
||||
|
||||
/**
|
||||
* 修改$!{table.comment}
|
||||
*
|
||||
* @param id $!{table.comment}ID
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
boolean update${entity}(Long id, ${entity}Form formData);
|
||||
|
||||
|
||||
/**
|
||||
* 删除$!{table.comment}
|
||||
*
|
||||
* @param ids $!{table.comment}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
*/
|
||||
boolean delete${entity}s(String ids);
|
||||
|
||||
}
|
||||
117
src/test/resources/templates/serviceImpl.java.vm
Normal file
117
src/test/resources/templates/serviceImpl.java.vm
Normal file
@@ -0,0 +1,117 @@
|
||||
package ${package.ServiceImpl};
|
||||
|
||||
import ${package.Entity}.${entity};
|
||||
import ${package.Mapper}.${table.mapperName};
|
||||
import ${package.Service}.${table.serviceName};
|
||||
import ${superServiceImplClassPackage};
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.youlai.common.util.DateUtils;
|
||||
import ${package.Parent}.model.form.${entity}Form;
|
||||
import ${package.Parent}.model.query.${entity}PageQuery;
|
||||
import ${package.Parent}.model.bo.${entity}BO;
|
||||
import ${package.Parent}.model.vo.${entity}PageVO;
|
||||
import ${package.Parent}.converter.${entity}Converter;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* $!{table.comment}服务实现类
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
|
||||
|
||||
private final ${entity}Converter ${firstCharLowerCaseEntity}Converter;
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}分页列表
|
||||
*
|
||||
* @param queryParams 查询参数
|
||||
* @return {@link IPage<${entity}PageVO>} $!{table.comment}分页列表
|
||||
*/
|
||||
@Override
|
||||
public IPage<${entity}PageVO> listPaged${entity}s(${entity}PageQuery queryParams) {
|
||||
|
||||
// 参数构建
|
||||
int pageNum = queryParams.getPageNum();
|
||||
int pageSize = queryParams.getPageSize();
|
||||
Page<${entity}BO> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
// 格式化为数据库日期格式,避免日期比较使用格式化函数导致索引失效
|
||||
DateUtils.toDatabaseFormat(queryParams, "startTime", "endTime");
|
||||
|
||||
// 查询数据
|
||||
Page<${entity}BO> boPage = this.baseMapper.listPaged${entity}s(page, queryParams);
|
||||
|
||||
// 实体转换
|
||||
return ${firstCharLowerCaseEntity}Converter.toPageVo(boPage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取$!{table.comment}表单数据
|
||||
*
|
||||
* @param id $!{table.comment}ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ${entity}Form get${entity}FormData(Long id) {
|
||||
${entity} entity = this.getById(id);
|
||||
return ${firstCharLowerCaseEntity}Converter.toForm(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增$!{table.comment}
|
||||
*
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean save${entity}(${entity}Form formData) {
|
||||
// 实体转换 form->entity
|
||||
${entity} entity = ${firstCharLowerCaseEntity}Converter.toEntity(formData);
|
||||
return this.save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新$!{table.comment}
|
||||
*
|
||||
* @param id $!{table.comment}ID
|
||||
* @param formData $!{table.comment}表单对象
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean update${entity}(Long id,${entity}Form formData) {
|
||||
${entity} entity = ${firstCharLowerCaseEntity}Converter.toEntity(formData);
|
||||
return this.updateById(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除$!{table.comment}
|
||||
*
|
||||
* @param ids $!{table.comment}ID,多个以英文逗号(,)分割
|
||||
* @return true|false
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entity}s(String ids) {
|
||||
Assert.isTrue(StrUtil.isNotBlank(ids), "删除的$!{table.comment}数据为空");
|
||||
// 逻辑删除
|
||||
List<Long> idList = Arrays.stream(ids.split(","))
|
||||
.map(Long::parseLong)
|
||||
.toList();
|
||||
return this.removeByIds(idList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
112
src/test/resources/templates/vo.java.vm
Normal file
112
src/test/resources/templates/vo.java.vm
Normal file
@@ -0,0 +1,112 @@
|
||||
package ${package.Parent}.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
#if(${entityLombokModel})
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
#if(${chainModel})
|
||||
import lombok.experimental.Accessors;
|
||||
#end
|
||||
#end
|
||||
|
||||
/**
|
||||
* $!{table.comment} VO
|
||||
*
|
||||
* @author ${author}
|
||||
* @since ${date}
|
||||
*/
|
||||
#if(${entityLombokModel})
|
||||
@Getter
|
||||
@Setter
|
||||
#if(${chainModel})
|
||||
@Accessors(chain = true)
|
||||
#end
|
||||
#end
|
||||
@Schema( description = "$!{table.comment}视图对象")
|
||||
#if(${superEntityClass})
|
||||
public class ${entity}VO extends ${superEntityClass}#if(${activeRecord})<${entity}>#end {
|
||||
#elseif(${activeRecord})
|
||||
public class ${entity} extends Model<${entity}> {
|
||||
#elseif(${entitySerialVersionUID})
|
||||
public class ${entity}VO implements Serializable {
|
||||
#else
|
||||
public class ${entity}VO {
|
||||
#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" != "")
|
||||
@Schema(description = "${field.comment}")
|
||||
#end
|
||||
|
||||
private ${field.propertyType} ${field.propertyName};
|
||||
#end
|
||||
## ---------- END 字段循环遍历 ----------
|
||||
#if(!${entityLombokModel})
|
||||
#foreach($field in ${table.fields})
|
||||
#if(${field.propertyType.equals("boolean")})
|
||||
#set($getprefix="is")
|
||||
#else
|
||||
#set($getprefix="get")
|
||||
#end
|
||||
|
||||
public ${field.propertyType} ${getprefix}${field.capitalName}() {
|
||||
return ${field.propertyName};
|
||||
}
|
||||
|
||||
#if(${chainModel})
|
||||
public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#else
|
||||
public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {
|
||||
#end
|
||||
this.${field.propertyName} = ${field.propertyName};
|
||||
#if(${chainModel})
|
||||
return this;
|
||||
#end
|
||||
}
|
||||
#end
|
||||
## --foreach 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
|
||||
#if(!${entityLombokModel})
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "${entity}{" +
|
||||
#foreach($field in ${table.fields})
|
||||
#if($!{foreach.index}==0)
|
||||
"${field.propertyName} = " + ${field.propertyName} +
|
||||
#else
|
||||
", ${field.propertyName} = " + ${field.propertyName} +
|
||||
#end
|
||||
#end
|
||||
"}";
|
||||
}
|
||||
#end
|
||||
}
|
||||
Reference in New Issue
Block a user