生成工具类类
package com.xxx.codegen;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.querys.MySqlQuery;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import com.baomidou.mybatisplus.generator.keywords.MySqlKeyWordsHandler;
import java.io.File;
import java.util.*;
/**
* @author momomian
* @date 2021/12/28
*/
public class CurdGenerator {
private static String author = "codegen";
private static String url = "jdbc:mysql://xxx.xx.x.xxx:3306/xxx-dev?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
private static String username = "xxx";
private static String password = "xxx";
//输出目录
private static String outputDir = System.getProperty("user.dir") + "/codegen/src/main/java";
//父包
private static String parentPackage = "com.xxx";
//模块名
private static String moduleName = "code";
//表名
private static String tableName = "all";//all表示所有
private static String tablePrefix = "sys_,doctor_,agent_,drug_,mer_,user_,doc,tms_,msg_";
// 表有无创建时间日期字段
private static boolean existDate = false;
private static String createDateName = "createDate";
private static String updateDateName = "updateDate";
// 全局响应类名
private static String allResultApiName = "R";
// 处理 all 情况
protected static List<String> getTables(String tables) {
return "all".equals(tables) ? Collections.emptyList() : Arrays.asList(tables.split(","));
}
/**
* 数据源配置
*/
private static final DataSourceConfig.Builder DATA_SOURCE_CONFIG = new DataSourceConfig
.Builder(url, username, password)
//数据库查询
.dbQuery(new MySqlQuery())
//数据库类型转换器
.typeConvert(new MySqlTypeConvert())
//数据库关键字处理器
.keyWordsHandler(new MySqlKeyWordsHandler());
/**
* 快速生成器
*/
private static FastAutoGenerator fastAutoGenerator = FastAutoGenerator.create(DATA_SOURCE_CONFIG);
public static void main(String[] args) {
genCode();
}
/**
* 全局配置
*/
public static void globalConfig() {
fastAutoGenerator.globalConfig(builder -> {
// 设置作者
builder.author(author)
// 开启 swagger 模式
.enableSwagger()
// 覆盖已生成文件
.fileOverride()
//禁止生成代码后自动弹出输出目录
.disableOpenDir()
// 时间策略
.dateType(DateType.TIME_PACK)
//注释日期,默认值: yyyy-MM-dd
.commentDate("yyyy-MM-dd")
// 指定输出目录
.outputDir(outputDir);
});
}
/**
* 包配置
*/
public static void packageConfig() {
fastAutoGenerator.packageConfig(builder -> {
// 设置父包名
builder.parent(parentPackage)
// 设置父包模块名
.moduleName(moduleName)
.entity("po")
// .service("service")
.serviceImpl("service.impl")
.mapper("mapper")
.xml("mapper.xml")
.controller("controller")
//设置自定义的文件包名,默认是other,这边取消掉
.other("")
// 设置mapperXml生成路径
.pathInfo(Collections.singletonMap(OutputFile.mapperXml, "codegen/src/main/resources/mapper"));
});
}
/**
* 基本模板配置
*/
public static void templateConfig() {
fastAutoGenerator.templateConfig((scanner, builder) -> builder
.entity("/template/entity.java")
.service("/template/service.java")
.serviceImpl("/template/serviceImpl.java")
.mapper("/template/mapper.java")
.mapperXml("/template/mapper.xml")
.controller("/template/controller.java")
);
}
/**
* 自定义模板配置
*/
public static void injectionConfig() {
Map<String, String> fileMap = new HashMap<>();
Map<String, Object> fieldMap = new HashMap<>();
fastAutoGenerator.injectionConfig(builder -> builder
//输出文件之前消费者
.beforeOutputFile((tableInfo, objectMap) -> {
String entityName = tableInfo.getEntityName();
Map<String, Object> aPackageMap = (Map) objectMap.get("package");
objectMap.put("table_name", entityName.substring(0, 1).toLowerCase() + entityName.substring(1));
objectMap.put("model", aPackageMap.get("Parent") + ".model");
objectMap.put("bean", entityName.replace("PO", ""));
objectMap.put("vo", entityName + "VO");
objectMap.put("convert", entityName + "Convert");
objectMap.put("dto", entityName + "DTO");
objectMap.put("query", entityName + "Query");
objectMap.put("common", "com.shuke.common");
diyConfig(objectMap);
//自定义生成文件配置
fileMap.put("/model/vo/" + entityName + "VO.java", "/template/vo.java.vm");
fileMap.put("/model/convert/" + entityName + "Convert.java", "/template/convert.java.vm");
fileMap.put("/model/dto/" + entityName + "DTO.java", "/template/dto.java.vm");
fileMap.put("/model/query/" + entityName + "Query.java", "/template/query.java.vm");
})
// 自定义属性,模板变量
.customMap(fieldMap)
.customFile(fileMap)
);
}
/**
* 自定义模板变量配置
* 主要用于生成一些特殊需求
*
* @param objectMap
*/
private static void diyConfig(Map<String, Object> objectMap) {
//设定entityLombokModel为true,使用lombok
objectMap.put("entityLombokModel", true);
//表有无创建时间日期字段
objectMap.put("existDate", existDate);
//时间字段set方法定义
objectMap.put("setCreateDate", "set" + createDateName.substring(0, 1).toUpperCase() + createDateName.substring(1));
objectMap.put("setUpdateDate", "set" + updateDateName.substring(0, 1).toUpperCase() + updateDateName.substring(1));
objectMap.put("ApiResult", allResultApiName);
objectMap.put("baseResultMap", true);
objectMap.put("baseColumnList", true);
}
/**
* 策略配置
*
* @return
*/
public static void strategyConfig() {
fastAutoGenerator.strategyConfig(builder -> {
// 设置需要生成的表名
builder.addInclude(getTables(tableName))
// 设置过滤表前缀
.addTablePrefix(tablePrefix)
.entityBuilder()
.enableLombok()
.logicDeleteColumnName("is_deleted")
.enableTableFieldAnnotation()
.controllerBuilder()
.enableRestStyle()
.mapperBuilder()
//生成通用的resultMap
.enableBaseResultMap()
.superClass(BaseMapper.class);
});
}
/**
* 配置模板引擎
*/
public static void templateEngine() {
fastAutoGenerator.templateEngine(new VelocityTemplateEngine() {
/**
* 重写输出自定义文件方法,自定义文件输出路径
*/
@Override
protected void outputCustomFile(Map<String, String> customFile, TableInfo tableInfo, Map<String, Object> objectMap) {
String otherPath = getPathInfo(OutputFile.other);
customFile.forEach((key, value) -> {
String fileName = String.format((otherPath + File.separator + "%s"), key);
outputFile(new File(fileName), objectMap, value);
});
customFile.clear();
}
});
}
public static void genCode() {
globalConfig();
packageConfig();
templateConfig();
strategyConfig();
injectionConfig();
templateEngine();
fastAutoGenerator.execute();
}
}
VM文件
package $!{package.Controller};
import ${common}.${ApiResult};
#if(${swagger})
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;
#end
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import $!{package.Entity}.$!{entity};
import $!{package.Service}.$!{table.serviceName};
import $!{model}.dto.$!{dto};
import $!{model}.vo.$!{vo};
import $!{model}.query.$!{query};
import $!{model}.convert.$!{convert};
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import com.xxx.jdbc.PageInfo;
#if(${restControllerStyle})
import org.springframework.web.bind.annotation.RestController;
#else
import org.springframework.stereotype.Controller;
#end
#if(${superControllerClassPackage})
import $!{superControllerClassPackage};
#end
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}控制器
*/
#if(${swagger})
@Api(value = "$!{table.comment}", tags = "$!{table.comment}")
#end
#if(${restControllerStyle})
@RestController
#else
@Controller
#end
@RequestMapping("${table_name}")
#if(${kotlin})
class ${table.controllerName}#if(${superControllerClass}) : $!{superControllerClass}()#end
#else
#if(${superControllerClass})
public class $!{table.controllerName} extends $!{superControllerClass} {
#else
public class $!{table.controllerName} {
#end
@Resource
private $!{table.serviceName} ${table_name}Service;
/**
* 获取$!{table.comment}分页列表
*/
#if(${swagger})
@ApiOperation(value = "获取$!{table.comment}分页列表", notes = "获取$!{table.comment}分页列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "current", required = false, value = "当前页", paramType = "form"),
@ApiImplicitParam(name = "size", required = false, value = "当前页大小", paramType = "form")
})
#end
@GetMapping(value = "/list/page")
public ${ApiResult}<PageInfo<$!{vo}>> list(#if(${swagger}) @ApiIgnore #end $!{query} query,#if(${swagger}) @ApiIgnore #end Page page) {
IPage<$!{entity}> pageList = ${table_name}Service.getWithPage(page, query);
PageInfo<$!{vo}> resultPage = $!{convert}.INSTANCE.toPageList(pageList);
return ${ApiResult}.ok(resultPage);
}
/**
* 根据ID获取$!{table.comment}详情
*/
#if(${swagger})
@ApiOperation(value = "根据ID获取$!{table.comment}详情", notes = "根据ID获取$!{table.comment}详情")
#end
@GetMapping("/get")
public ${ApiResult}<$!{vo}> get(@RequestParam("id") Long id) {
$!{entity} entity = ${table_name}Service.getById(id);
$!{vo} vo = $!{convert}.toVo(entity);
return ${ApiResult}.ok(vo);
}
/**
* 新增${table.comment}
*/
#if(${swagger})
@ApiOperation(value = "新增${table.comment}", notes = "新增${table.comment}")
@ApiImplicitParams({
#foreach($field in ${table.fields})
#if(!${field.keyFlag})
#if(${foreach.count}==${table.fields.size()})
@ApiImplicitParam(name = "${field.propertyName}", required = false, value = "${field.comment}", paramType = "form")
#else
@ApiImplicitParam(name = "${field.propertyName}", required = false, value = "${field.comment}", paramType = "form"),
#end
#end
#end
})
#end
@PostMapping("/add")
public ${ApiResult}<String> add(#if(${swagger}) @ApiIgnore #end @RequestBody $!{dto} dto) {
${entity} po = ${bean}Convert.toPO(dto);
#if(${existDate})
po.${setCreateDate}(LocalDateTime.now());
po.${setUpdateDate}(LocalDateTime.now());
#end
boolean save = ${table_name}Service.save(po);
return save ? ${ApiResult}.ok() : ${ApiResult}.failed();
}
/**
*编辑${table.comment}
*/
#if(${swagger})
@ApiOperation(value = "编辑${table.comment}", notes = "编辑${table.comment}")
@ApiImplicitParams({
#foreach($field in ${table.fields})
#if(${foreach.count}==${table.fields.size()})
@ApiImplicitParam(name = "${field.propertyName}", required = false, value = "${field.comment}", paramType = "form")
#else
@ApiImplicitParam(name = "${field.propertyName}", required = false, value = "${field.comment}", paramType = "form"),
#end
#end
})
#end
@PostMapping("/update")
public ${ApiResult} update(#if(${swagger}) @ApiIgnore #end @RequestBody $!{dto} dto) {
${entity} po = ${bean}Convert.toPO(dto);
#if(${existDate})
po.${setUpdateDate}(LocalDateTime.now());
#end
boolean update = ${table_name}Service.updateById(po);
return update ? ${ApiResult}.ok() : ${ApiResult}.failed();
}
## /**
## *移除${table.comment}
## */
## #if(${swagger})
## @ApiOperation(value = "移除$!{table.comment}", notes = "移除$!{table.comment}")
## @ApiImplicitParams({
## @ApiImplicitParam(name = "id", required = true, value = "$!{table.comment}id", paramType = "form")
## })
## #end
## @PostMapping("/remove")
## public ${ApiResult}<String> remove(@RequestParam(value = "id") Long id) {
## boolean remove = ${table_name}Service.removeById(id);
## return remove ? ${ApiResult}.ok() : ${ApiResult}.failed();
## }
}
#end
package $!{model}.convert;
import $!{package.Entity}.$!{entity};
import ${model}.dto.$!{dto};
import ${model}.vo.$!{vo};
import java.util.ArrayList;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xxx.jdbc.PageInfo;
import org.mapstruct.ReportingPolicy;
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}转换类
*/
@Mapper(componentModel = "spring",unmappedSourcePolicy = ReportingPolicy.IGNORE, unmappedTargetPolicy = ReportingPolicy.IGNORE )
public interface $!{convert} {
$!{entity} INSTANCE = Mappers.getMapper($!{entity}.class);
$!{vo} toVo($!{entity} po);
List<$!{vo}> toVo(List<$!{entity}> pos);
$!{dto} toDto($!{entity} po);
List<$!{dto}> toDto(List<$!{entity}> po);
PageInfo<$!{vo}> toPageList(IPage<$!{entity}> pos);
$!{entity} toPo($!{dto} dto);
}
package $!{model}.dto;
#if(${swagger})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
#foreach($pkg in ${table.importPackages})
import $!{pkg};
#end
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}转换类
*/
@Data
@NoArgsConstructor
#if(${swagger})
@ApiModel(value="$!{table.comment}转换对象")
#end
public class $!{dto} implements Serializable {
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${swagger})
@ApiModelProperty(value = "$!{field.comment}")
#else
/**
* $!{field.comment}
*/
#end
#end
private $!{field.propertyType} $!{field.propertyName};
#end
## ---------- END 字段循环遍历 ----------
}
package $!{package.Entity};
#foreach($pkg in ${table.importPackages})
import $!{pkg};
#end
#if(${entityLombokModel})
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
#end
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}实体对象
*/
#if(${entityLombokModel})
@Data
#if(${superEntityClass})
@EqualsAndHashCode(callSuper = true)
#else
@EqualsAndHashCode(callSuper = false)
#end
@NoArgsConstructor
#end
#if(${table.convert})
@TableName("$!{table.name}")
#end
#if(${superEntityClass})
public class $!{entity} extends $!{superEntityClass}#if(${activeRecord})<$!{entity}>#end {
#elseif(${activeRecord})
public class $!{entity} extends Model<$!{entity}> {
#else
public class $!{entity} implements Serializable {
#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.name}", type = IdType.AUTO)
#elseif(!$null.isNull(${idType}) && "$!idType" != "")
@TableId(value = "$!{field.name}", type = IdType.$!{idType})
#elseif(${field.convert})
@TableId("$!{field.name}")
#end
## 普通字段
#elseif(${field.fill})
## ----- 存在字段填充设置 -----
#if(${field.convert})
@TableField(value = "$!{field.name}", fill = FieldFill.$!{field.fill})
#else
@TableField(fill = FieldFill.$!{field.fill})
#end
#elseif(${field.convert})
#end
## 乐观锁注解
#if(${versionFieldName}==${field.name})
@Version
#end
## 逻辑删除注解
#if(${logicDeleteFieldName}==${field.name})
@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(${entityBuilderModel})
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(${entityBuilderModel})
return this;
#end
}
#end
#end
#if(${entityColumnConstant})
#foreach($field in ${table.fields})
public static final String $!{field.name.toUpperCase()} = "$!{field.name}";
#end
#end
#if(${activeRecord})
@Override
protected 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}
"$!{field.propertyName}=" + $!{field.propertyName} +
#else
", $!{field.propertyName}=" + $!{field.propertyName} +
#end
#end
"}";
}
#end
}
package $!{package.Mapper};
import $!{package.Entity}.$!{entity};
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import $!{model}.query.$!{query};
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment} Mapper 接口
*/
#if(${kotlin})
interface $!{table.mapperName} : $!{superMapperClass}<$!{entity}>
#else
@Repository
public interface $!{table.mapperName} extends $!{superMapperClass}<$!{entity}> {
IPage<$!{entity}> getWithPage(Page page, @Param("query") $!{query} query);
/**
* 新增后返回id
* @param po
* @return
*/
@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
Long insertReturnId(@Param("po") $!{entity} po);
int getCountByQuery(@Param("query") ${query} query);
$!{entity} getOneByQuery(@Param("query") ${query} query);
List<$!{entity}> getAllByQuery(@Param("query") ${query} query);
}
#end
<?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="org.mybatis.caches.ehcache.LoggingEhcache"/>
#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.name},
#end
${table.fieldNames}
</sql>
#end
<!-- 表名 -->
<sql id="t_name">${table.name}</sql>
<!-- 别名 -->
#set($i=${table.name.lastIndexOf('_')})
#set($alias=${table.name.substring($i+1)})
<sql id="t_alias">${table.name} as ${alias}</sql>
<select id="getWithPage" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM ${table.name}
<where>
#foreach($field in ${table.fields})
<if test="query.${field.propertyName} != null ">
and ${field.name} = #{query.${field.propertyName}}
</if>
#end
</where>
</select>
<select id="getCountByQuery" resultType="java.lang.Integer">
select count(1)
from ${table.name}
<where>
#foreach($field in ${table.fields})
<if test="query.${field.propertyName} != null ">
and ${field.name} = #{query.${field.propertyName}}
</if>
#end
</where>
</select>
<insert id="insertReturnId" parameterType="$!{package.Entity}.$!{entity}" useGeneratedKeys="true" keyProperty="id">
INSERT INTO ${table.name}(
<trim suffixOverrides=",">
#foreach($field in ${table.fields})
<if test="po.${field.propertyName} != null">
${field.name} ,
</if>
#end
</trim>
)VALUES(
<trim suffixOverrides=",">
#foreach($field in ${table.fields})
<if test="po.${field.propertyName} != null">
#{po.${field.propertyName}},
</if>
#end
</trim>
)
</insert>
<select id="getOneByQuery" resultType="$!{package.Entity}.$!{entity}">
select <include refid="Base_Column_List"/>
from ${table.name}
<where>
#foreach($field in ${table.fields})
<if test="query.${field.propertyName} != null ">
and ${field.name} = #{query.${field.propertyName}}
</if>
#end
</where>
</select>
<select id="getAllByQuery" resultType="$!{package.Entity}.$!{entity}">
select <include refid="Base_Column_List"/>
from ${table.name}
<where>
#foreach($field in ${table.fields})
<if test="query.${field.propertyName} != null ">
and ${field.name} = #{query.${field.propertyName}}
</if>
#end
</where>
</select>
</mapper>
package $!{model}.query;
#if(${swagger})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
import lombok.Data;
import lombok.NoArgsConstructor;
#foreach($pkg in ${table.importPackages})
import $!{pkg};
#end
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}查询类
*/
@Data
@NoArgsConstructor
#if(${swagger})
@ApiModel(value="$!{table.comment}查询对象")
#end
public class $!{query} implements Serializable {
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${swagger})
@ApiModelProperty(value = "$!{field.comment}")
#else
/**
* $!{field.comment}
*/
#end
#end
private $!{field.propertyType} $!{field.propertyName};
#end
## ---------- END 字段循环遍历 ----------
}
package $!{package.Service};
import $!{package.Entity}.$!{entity};
import $!{superServiceClassPackage};
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import $!{model}.dto.$!{dto};
import $!{model}.query.$!{query};
import java.util.List;
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment} 服务类
*/
#if($!{kotlin})
interface $!{table.serviceName} : $!{superServiceClass}<$!{entity}>
#else
public interface $!{table.serviceName} extends $!{superServiceClass}<$!{entity}> {
IPage<$!{entity}> getWithPage(Page page, $!{query} query);
$!{entity} getOneByQuery(${query} query);
List<$!{entity}> getAllByQuery( ${query} query);
}
#end
package $!{package.ServiceImpl};
import $!{package.Entity}.$!{entity};
import $!{package.Mapper}.$!{table.mapperName};
import $!{package.Service}.$!{table.serviceName};
import $!{superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import $!{model}.dto.$!{dto};
import $!{model}.vo.$!{vo};
import $!{model}.query.$!{query};
import java.util.List;
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment} 服务实现类
*/
@Service
@Transactional(rollbackFor = Exception.class)
#if($!{kotlin})
open class $!{table.serviceImplName} : $!{superServiceImplClass}<$!{table.mapperName}, $!{entity}>(), $!{table.serviceName} {
}
#else
public class $!{table.serviceImplName} extends $!{superServiceImplClass}<$!{table.mapperName}, $!{entity}> {
## @Override
public IPage<$!{entity}> getWithPage(Page page, $!{query} query) {
return baseMapper.getWithPage(page, query);
}
## @Override
public $!{entity} getOneByQuery($!{query} query) {
return baseMapper.getOneByQuery(query);
}
## @Override
public List<$!{entity}> getAllByQuery($!{query} query) {
return baseMapper.getAllByQuery(query);
}
}
#end
package $!{model}.vo;
#if(${swagger})
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#end
import lombok.Data;
import lombok.NoArgsConstructor;
#foreach($pkg in ${table.importPackages})
import $!{pkg};
#end
/**
* @author $!{author}
* @date $!{date}
* @description $!{table.comment}视图对象
*/
@Data
@NoArgsConstructor
#if(${swagger})
@ApiModel(value="$!{vo}视图对象")
#end
public class $!{vo} implements Serializable {
private static final long serialVersionUID = 1L;
## ---------- BEGIN 字段循环遍历 ----------
#foreach($field in ${table.fields})
#if(${field.keyFlag})
#set($keyPropertyName=${field.propertyName})
#end
#if("$!field.comment" != "")
#if(${swagger})
@ApiModelProperty(value = "$!{field.comment}")
#else
/**
* $!{field.comment}
*/
#end
#end
private $!{field.propertyType} $!{field.propertyName};
#end
## ---------- END 字段循环遍历 ----------
}
properties文件
#\u4EE3\u7801\u751F\u6210\u5668\uFF0C\u914D\u7F6E\u4FE1\u606F
mainPath=com.xxx
#\u5305\u540D
package=com.xxx
moduleName=generator
#\u4F5C\u8005
author=shuke code generator
#\u8868\u524D\u7F00(\u7C7B\u540D\u4E0D\u4F1A\u5305\u542B\u8868\u524D\u7F00)
tablePrefix=table_
#\u7C7B\u578B\u8F6C\u6362\uFF0C\u914D\u7F6E\u4FE1\u606F
tinyint=Integer
smallint=Integer
mediumint=Integer
int=Integer
integer=Integer
bigint=Long
float=Float
double=Double
decimal=BigDecimal
bit=Boolean
char=String
bpchar=String
varchar=String
tinytext=String
text=String
mediumtext=String
longtext=String
date=LocalDate
datetime=LocalDateTime
timestamp=LocalDateTime