mybatis-plus自controller开始一键生成CURD代码

效果展示

以生成employee表对应的CURD为例

  • 生成的文件
    在这里插入图片描述
  • controller里面长这样
    在这里插入图片描述

使用方式

  • 第一步:引入下方的给出的相关依赖
  • 第二步:将下方的单元测试类直接贴进去
  • 第三步:运行单元测试即可
    注:本人测试用的是junit5,如果用的是junit4的话,简单改一下即可

相关依赖

<!-- mybatis-plus -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.5.2</version>
</dependency>

<!-- 代码生成器相关 -->
<dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.5.2</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.30</version>
    <scope>test</scope>
</dependency>

<!--  IOUtil、PathUtil工具类包 -->
<dependency>
    <groupId>com.idea-aedi</groupId>
    <artifactId>common-ds</artifactId>
    <version>2100.5.2</version>
</dependency>

代码生成器单元测试类

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.ConstVal;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateConfig;
import com.baomidou.mybatisplus.generator.config.builder.Entity;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.po.TableField;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.ideaaedi.commonds.io.IOUtil;
import com.ideaaedi.commonds.path.PathUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.lang.NonNull;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * mybatis-plus代码生成 &emsp;
 * <a href="https://baomidou.com/pages/779a6e/#%E4%BD%BF%E7%94%A8">代码生成官网</a>
 * &emsp;
 * <a href="https://baomidou.com/pages/981406/#%E5%9F%BA%E7%A1%80%E9%85%8D%E7%BD%AE">配置说明官网</a>
 *
 * @author JustryDeng
 * @since 2022/6/28 9:26
 */
@SpringBootTest
public class MybatisPlusGeneratorHelper {
    
    private static final String templateDir = "mybatis-plus-templates";
    
    @Value("${spring.datasource.url}")
    private String url;
    
    @Value("${spring.datasource.username}")
    private String username;
    
    @Value("${spring.datasource.password}")
    private String password;
    
    /**
     * true-使用自定义模板; false-使用默认模板
     */
    private static final boolean useCustomTemplate = true;
    
    /*
     * 自动生成模板文件
     */
    static {
        if (useCustomTemplate) {
            final String customTemplatesDirRePath = "/src/test/resources/" + templateDir + "/";
            String customTemplatesDirPath = PathUtil.getProjectRootDir(MybatisPlusGeneratorHelper.class)
                    .replace("/target/test-classes/", customTemplatesDirRePath);
            File customTemplatesDir = new File(customTemplatesDirPath);
            if (!customTemplatesDir.exists()) {
                System.err.println(MybatisPlusGeneratorHelper.class.getSimpleName() + ":自定义的模板文件不存在, 自动创建开始. 创建至:" + customTemplatesDirRePath);
                // TODO 将这三个类拷贝到自己的项目下,然后将这里的BaseDTO.class、BasePageDTO.class、 PageInfo.class换成自己的即可
                final String baseDTOName = YourBaseClass.BaseDTO.class.getName().replace("$", ".");
                final String basePageDTOName = YourBaseClass.BasePageDTO.class.getName().replace("$", ".");
                final String PageInfoName = YourBaseClass.PageInfo.class.getName().replace("$", ".");
                for (JustryDengTemplates templateInfo : JustryDengTemplates.values()) {
                    IOUtil.writeContentToFile(
                            templateInfo.getContent()
                                    .replace("JustryDeng_Placeholder.BaseDTO", baseDTOName)
                                    .replace("JustryDeng_Placeholder.BasePageDTO", basePageDTOName)
                                    .replace("JustryDeng_Placeholder.PageInfo", PageInfoName),
                            new File(customTemplatesDir, templateInfo.name));
                }
                System.err.println(MybatisPlusGeneratorHelper.class.getSimpleName() + ":自定义的模板文件创建完成. 请重新运行单元测试以生成相关文件.");
                System.exit(-1);
            }
        }
    }
    
    @Test
    void generate() {
        String outputRootDir = PathUtil.getProjectRootDir(MybatisPlusGeneratorHelper.class)
                .replace("/target/test-classes/", "/src/test/java/");
        String packagePath = MybatisPlusGeneratorHelper.class.getPackage().getName() + ".generator";
        // 先清空./generator/目录
        IOUtil.delete(new File(outputRootDir + packagePath.replace(".", "/")));
        
        
        // basic settings
        final FastAutoGenerator fastAutoGenerator = FastAutoGenerator
                .create(
                        new DataSourceConfig
                                .Builder(url, username, password)
                        ///.typeConvert((globalConfig, fieldType) -> {
                        ///    String columeType = fieldType.toLowerCase();
                        ///    if (columeType.contains("tinyint")) {
                        ///        return DbColumnType.INTEGER;
                        ///    }
                        ///    // 其它字段采用默认转换
                        ///    return new MySqlTypeConvert().processTypeConvert(globalConfig, fieldType);
                        ///})
                )
                .globalConfig(builder -> builder
                                // 设置作者
                                .author("mybatis-plus generator")
                                .commentDate("yyyy-MM-dd HH:mm:ss")
                                // 指定输出目录
                                .outputDir(outputRootDir)
                        // 开启swagger模式
                        //.enableSwagger()
                )
                // 包配置
                .packageConfig(builder -> builder
                        // 指定生成的类的所属包
                        .parent(packagePath)
                        .entity("entity.po")
                        .service("service")
                        .serviceImpl("service.impl")
                        .mapper("mapper")
                        .xml("mapper.xml")
                        .controller("controller")
                        .other("other"))
                // 策略配置
                .strategyConfig(builder -> builder
                        // => 表配置
                        // 设置需要生成代码的表名(不设置则全库生成) TODO
                        ///                       .addInclude(
                        ///                                "user_face_rec_info"
                        ///                        )
                        // 设置过滤表前缀
                        // .addTablePrefix("tmp_")
                        // 设置过滤表后缀
                        // .addTableSuffix("_tmp")
                        
                        // => entity配置
                        .entityBuilder()
                        .convertFileName((entityName) -> entityName + "PO")
                        /// 给po设置公共父类
                        ///.superClass(PoSupperEntity.class)
                        /// 设置生成的PO里面的对应字段有填充标识或者逻辑删除标识
                        /// // 逻辑删除字段名
                        /// .logicDeletePropertyName("del")
                        /// // 自动填充
                        /// .addTableFills(new Property("createdBy", FieldFill.INSERT))
                        /// .addTableFills(new Property("createdAt", FieldFill.INSERT))
                        /// .addTableFills(new Property("updatedBy", FieldFill.UPDATE))
                        /// .addTableFills(new Property("updatedAt", FieldFill.UPDATE))
                        // 启用TableField等相关注解
                        .enableTableFieldAnnotation()
                        .enableLombok()
                        
                        // => controller配置
                        .controllerBuilder()
                        .enableRestStyle()
                        .convertFileName((entityName) -> entityName + "Controller")
                        // .superClass(BaseController.class)
                        
                        // => service配置
                        .serviceBuilder()
                        .convertServiceFileName((entityName) -> entityName + "Service")
                        .convertServiceImplFileName((entityName) -> entityName + "ServiceImpl")
                        
                        // => mapper配置
                        .mapperBuilder()
                        .enableMapperAnnotation()
                        .convertMapperFileName((entityName) -> entityName + "Mapper")
                        .convertXmlFileName((entityName) -> entityName + "Mapper"))
                .templateEngine(useCustomTemplate ? new EnhanceFreemarkerTemplateEngine() : new FreemarkerTemplateEngine());
        
        // entity、service、serviceImpl、controller、mapper、xml,使用指定模板生成
        fastAutoGenerator.templateConfig((TemplateConfig.Builder builder) -> {
            if (useCustomTemplate) {
                /*
                 * 使用自定义的模板
                 * 注:参考mybatis-plus-generator包下的默认模板进行编写即可
                 * 注:自定义的模板放在classpath下的对应位置即可
                 * 注:指定模板时,无需带对应的模板后缀名(如:这里不带.ftl)
                 */
                builder
                        .entity("/" + templateDir + "/" + "custom_entity")
                        .service("/" + templateDir + "/" + "custom_service")
                        .serviceImpl("/" + templateDir + "/" + "custom_serviceImpl")
                        .controller("/" + templateDir + "/" + "custom_controller")
                        // 不改的话,用默认的即可
                        .mapper(ConstVal.TEMPLATE_MAPPER)
                        .xml(ConstVal.TEMPLATE_XML);
            } else {
                // 使用mybatis-plus-generator包下的默认模板
                builder
                        .entity(ConstVal.TEMPLATE_ENTITY_JAVA)
                        .mapper(ConstVal.TEMPLATE_MAPPER)
                        .xml(ConstVal.TEMPLATE_XML)
                        .service(ConstVal.TEMPLATE_SERVICE)
                        .serviceImpl(ConstVal.TEMPLATE_SERVICE_IMPL)
                        .controller(ConstVal.TEMPLATE_CONTROLLER);
            }
        });
        
        fastAutoGenerator.execute();
    }
    
    
    /**
     * 您的项目中需要这三种类<br />
     */
    public static class YourBaseClass {
        /**
         * 基础模型
         *
         * @author JustryDeng
         * @since 2022/6/24 10:00
         */
        @Setter
        @Getter
        @ToString
        public static class BaseDTO implements Serializable {
            
            private static final long serialVersionUID = -1;
        }
        
        /**
         * 基础模型
         *
         * @author JustryDeng
         * @since 2022/6/24 10:00
         */
        @Setter
        @Getter
        @ToString
        @SuppressWarnings({"AlibabaPojoNoDefaultValue", "AlibabaPojoMustUsePrimitiveField"})
        public static class BasePageDTO extends BaseDTO {
            
            /** 页码 */
            private int pageNum = 1;
            
            /** 每页条数 */
            private int pageSize = 10;
        }
        
        /**
         * 分页信息模型
         *
         * @author kuoyi
         * @since 1.0.0
         */
        @Data
        
        public static class PageInfo<T> {
            
            /** 总条数 */
            private long total;
            
            /** 页码 */
            private int pageNum;
            
            /** 每页条数 */
            private int pageSize;
            
            /** 数据集 */
            private List<T> dataList;
            
            /**
             * 快速构造
             */
            @SuppressWarnings("unused")
            public static <T> PageInfo<T> of(long total, int pageNum, int pageSize) {
                return PageInfo.of(total, pageNum, pageSize, Collections.emptyList());
            }
            
            /**
             * 快速构造
             */
            public static <T> PageInfo<T> of(long total, int pageNum, int pageSize, List<T> dataList) {
                PageInfo<T> pageInfo = new PageInfo<>();
                pageInfo.setTotal(total);
                pageInfo.setPageNum(pageNum);
                pageInfo.setPageSize(pageSize);
                pageInfo.setDataList(dataList);
                return pageInfo;
            }
        }
        
    }
    
    /* --------------------------------------------------------------- 以下部分,可以不关心 --------------------------------------------------------------- */
    
    
    /**
     * 扩展FreemarkerTemplateEngine,生成更多相关文件
     */
    public static class EnhanceFreemarkerTemplateEngine extends FreemarkerTemplateEngine {
        
        /**
         * (non-javadoc)
         *
         * @param customFile
         *         自定义文件; key-生成的文件; value-生成该文件使用的(classpath下的带模板文件后缀名的)模板文件
         * @param tableInfo
         *         表信息
         * @param objectMap
         *         模板可使用的占位符即对应变量值(即:objectMap里的key可以在模板文件中直接引用)
         */
        @Override
        protected void outputCustomFile(@NonNull Map<String, String> customFile, @NonNull TableInfo tableInfo,
                                        @NonNull Map<String, Object> objectMap) {
            String entityName = tableInfo.getEntityName();
            String entityPath = this.getPathInfo(OutputFile.entity);
            String originEntityName;
            if (entityName.endsWith("PO")) {
                originEntityName = entityName.substring(0, entityName.length() - 2);
            } else {
                originEntityName = entityName;
            }
            // 自定义一些key-value,以便在模板中获取对应的值
            String comment = tableInfo.getComment();
            String originEntityNameHyphenStyle = StringUtils.camelToHyphen(originEntityName);
            objectMap.put("originEntityName", originEntityName);
            objectMap.put("customLowerServiceName", StringUtils.firstToLowerCase(tableInfo.getServiceName()));
            objectMap.put("originEntityNameHyphenStyle", originEntityNameHyphenStyle);
            objectMap.put("briefTableComment", StringUtils.isNotBlank(comment) ? comment.replace("表", "").trim() : originEntityNameHyphenStyle);
            Set<String> importPackages = tableInfo.getImportPackages();
            
            String superClassLongName;
            List<String> superClassImportList;
            try {
                Field entityField = TableInfo.class.getDeclaredField("entity");
                entityField.setAccessible(true);
                Entity entity = (Entity)entityField.get(tableInfo);
                superClassLongName = entity.getSuperClass();
                superClassImportList = Arrays.stream(Class.forName(superClassLongName).getDeclaredFields())
                        .map(field -> field.getType().getName())
                        .filter(x -> !x.startsWith("java.lang.")).collect(Collectors.toList());
            } catch (Exception e) {
                superClassLongName = null;
                superClassImportList = null;
                logger.warn(e.getMessage());
            }
            String finalSuperClassImport = superClassLongName;
            LinkedHashSet<String> importPackageList = new LinkedHashSet<>(importPackages);
            if (!CollectionUtils.isEmpty(superClassImportList)) {
                importPackageList.addAll(superClassImportList);
            }
            Set<String> customImportPackages = importPackageList.stream()
                    .filter(pack -> {
                        if ("java.io.Serializable".equals(pack)) {
                            return false;
                        }
                        if (pack.equals(finalSuperClassImport)) {
                            return false;
                        }
                        return !pack.startsWith("com.baomidou.");
                    }).collect(Collectors.toCollection(TreeSet::new));
            objectMap.put("customImportPackages", customImportPackages);
            
            List<TableField> customAllFields = new ArrayList<>(32);
            List<TableField> commonFields = tableInfo.getCommonFields();
            if (!CollectionUtils.isEmpty(commonFields)) {
                customAllFields.addAll(commonFields);
            }
            List<TableField> fields = tableInfo.getFields();
            if (!CollectionUtils.isEmpty(fields)) {
                customAllFields.addAll(fields);
            }
            objectMap.put("customAllFields", customAllFields);
            
            /// customFile.forEach((key, value) -> {
            ///     String fileName = String.format(entityPath + File.separator + entityName + "%s", key);
            ///     this.outputFile(new File(fileName), objectMap, value, true); 参数分别是:要生成的文件, 模板可以取的参数,
            // classpath下的模板文件(带模板文件后缀名), 是否覆盖已有文件
            /// });
            // 生成xxxAddReqVO
            this.outputFile(new File(entityPath + File.separator + "req" + File.separator + originEntityName +
                    "AddReqVO.java"), objectMap, "/" + templateDir + "/PojoAddReqVO.ftl", true);
            // 生成xxxUpdateReqVOentityPath + File.separator + "req" + File.separator + originEntityName + "AddReqVO
            // .java" = "E:/Git/Repository/part-time-job/pension-platform-java/pension-basic/src/test/java/\com
            // \ideaaedi\smart\pension\basic\mybatisPlus\generator\entity\po\req\CmMonitorInfoAddReqVO.java"
            this.outputFile(new File(entityPath + File.separator + "req" + File.separator + originEntityName +
                    "UpdateReqVO.java"), objectMap, "/" + templateDir + "/PojoUpdateReqVO.ftl", true);
            // 生成xxxListReqVO
            this.outputFile(new File(entityPath + File.separator + "req" + File.separator + originEntityName +
                    "ListReqVO.java"), objectMap, "/" + templateDir + "/PojoListReqVO.ftl", true);
            // 生成xxxListRespVO
            this.outputFile(new File(entityPath + File.separator + "resp" + File.separator + originEntityName +
                    "ListRespVO.java"), objectMap, "/" + templateDir + "/PojoListRespVO.ftl", true);
            // 生成xxxDetailRespVO
            this.outputFile(new File(entityPath + File.separator + "resp" + File.separator + originEntityName +
                            "DetailRespVO.java"), objectMap, "/" + templateDir + "/PojoDetailRespVO.ftl",
                    true);
        }
    }
    
    /**
     * 自定义的模板
     */
    @Getter
    @SuppressWarnings("FieldCanBeLocal")
    public enum JustryDengTemplates {
        custom_controller("custom_controller.ftl", "package ${package.Controller};\n"
                + "\n"
                + "import ${package.Entity}.req.${originEntityName}AddReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}ListReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}UpdateReqVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}DetailRespVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}ListRespVO;\n"
                + "import ${package.Service}.${table.serviceName};\n"
                + "import JustryDeng_Placeholder.PageInfo;\n"
                + "<#if superControllerClassPackage??>\n"
                + "import ${superControllerClassPackage};\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.Api;\n"
                + "import io.swagger.annotations.ApiOperation;\n"
                + "</#if>\n"
                + "import org.springframework.validation.annotation.Validated;\n"
                + "import org.springframework.web.bind.annotation.PathVariable;\n"
                + "import org.springframework.web.bind.annotation.PostMapping;\n"
                + "import org.springframework.web.bind.annotation.RequestBody;\n"
                + "import org.springframework.web.bind.annotation.RequestMapping;\n"
                + "import org.springframework.web.bind.annotation.RequestMethod;\n"
                + "<#if restControllerStyle>\n"
                + "import org.springframework.web.bind.annotation.RestController;\n"
                + "<#else>\n"
                + "import org.springframework.stereotype.Controller;\n"
                + "</#if>\n"
                + "\n"
                + "import javax.annotation.Resource;\n"
                + "import javax.validation.constraints.NotNull;\n"
                + "\n"
                + "/**\n"
                + " * ${briefTableComment}\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "@Validated\n"
                + "<#if restControllerStyle>\n"
                + "@RestController\n"
                + "<#else>\n"
                + "@Controller\n"
                + "</#if>\n"
                + "@RequestMapping(\"<#if package.ModuleName?? && package.ModuleName != \"\">/${package"
                + ".ModuleName}</#if>/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>$"
                + "{originEntityNameHyphenStyle}</#if>\")\n"
                + "<#if swagger>\n"
                + "@Api(value = \"${briefTableComment}\", tags = {\"${briefTableComment}\"})\n"
                + "</#if>\n"
                + "<#if kotlin>\n"
                + "class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>\n"
                + "<#else>\n"
                + "<#if superControllerClass??>\n"
                + "public class ${table.controllerName} extends ${superControllerClass} {\n"
                + "<#else>\n"
                + "public class ${table.controllerName} {\n"
                + "</#if>\n"
                + "\n"
                + "    @Resource\n"
                + "    private ${table.serviceName} ${customLowerServiceName};\n"
                + "\n"
                + "    /**\n"
                + "     * 增\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 新增的数据详情\n"
                + "     */\n"
                + "    @PostMapping(\"/add\")\n"
                + "    <#if swagger>\n"
                + "    @ApiOperation(value = \"增\")\n"
                + "    </#if>\n"
                + "    public ${originEntityName}DetailRespVO add(@RequestBody @Validated ${originEntityName}AddReqVO"
                + " req) {\n"
                + "        return ${customLowerServiceName}.add(req);\n"
                + "    }\n"
                + "\n"
                + "    /**\n"
                + "     * 删\n"
                + "     *\n"
                + "     * @param id\n"
                + "     *         要删除数据的id\n"
                + "     *\n"
                + "     * @return 删除了的数据详情\n"
                + "     */\n"
                + "    <#if swagger>\n"
                + "    @ApiOperation(value = \"删\")\n"
                + "    </#if>\n"
                + "    @RequestMapping(value = \"/delete/{id}\", method = {RequestMethod.POST, RequestMethod.DELETE})\n"
                + "    public ${originEntityName}DetailRespVO delete(@PathVariable(\"id\") @NotNull(message = \"id "
                + "cannot be null.\") <#list customAllFields as field><#if field.keyFlag>${field"
                + ".propertyType}</#if></#list> id) {\n"
                + "        return ${customLowerServiceName}.delete(id);\n"
                + "    }\n"
                + "\n"
                + "    /**\n"
                + "     * 改\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 修改后的数据详情\n"
                + "     */\n"
                + "    <#if swagger>\n"
                + "    @ApiOperation(value = \"改\")\n"
                + "    </#if>\n"
                + "    @RequestMapping(value = \"/update\", method = {RequestMethod.POST, RequestMethod.PUT})\n"
                + "    public ${originEntityName}DetailRespVO update(@RequestBody @Validated "
                + "${originEntityName}UpdateReqVO req) {\n"
                + "        return ${customLowerServiceName}.update(req);\n"
                + "    }\n"
                + "\n"
                + "    /**\n"
                + "     * 查详情\n"
                + "     *\n"
                + "     * @param id\n"
                + "     *         要查询数据的id\n"
                + "     *\n"
                + "     * @return 数据详情\n"
                + "     */\n"
                + "    <#if swagger>\n"
                + "    @ApiOperation(value = \"查详情\")\n"
                + "    </#if>\n"
                + "    @RequestMapping(value = \"/detail/{id}\", method = {RequestMethod.POST, RequestMethod.GET})\n"
                + "    public ${originEntityName}DetailRespVO detail(@PathVariable(\"id\") @NotNull(message = \"id "
                + "cannot be null.\") <#list customAllFields as field><#if field.keyFlag>${field"
                + ".propertyType}</#if></#list> id) {\n"
                + "        return ${customLowerServiceName}.detail(id);\n"
                + "    }\n"
                + "\n"
                + "    /**\n"
                + "     * 查列表\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 数据列表\n"
                + "     */\n"
                + "    @PostMapping(\"/list\")\n"
                + "    <#if swagger>\n"
                + "    @ApiOperation(value = \"查列表\")\n"
                + "    </#if>\n"
                + "    public PageInfo<${originEntityName}ListRespVO> list(@RequestBody @Validated "
                + "${originEntityName}ListReqVO req) {\n"
                + "        return ${customLowerServiceName}.list(req);\n"
                + "    }\n"
                + "\n"
                + "}\n"
                + "</#if>\n"),
        custom_entity("custom_entity.ftl", "package ${package.Entity};\n"
                + "\n"
                + "<#list table.importPackages as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "    <#if superEntityClass??>\n"
                + "import lombok.EqualsAndHashCode;\n"
                + "    </#if>\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} po模型\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "    <#if superEntityClass??>\n"
                + "@EqualsAndHashCode(callSuper = true)\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "<#if table.convert>\n"
                + "@TableName(\"${schemaName}${table.name}\")\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${entity}对象\", description = \"${table.comment!}\")\n"
                + "</#if>\n"
                + "<#if superEntityClass??>\n"
                + "public class ${entity} extends ${superEntityClass}<#if activeRecord><${entity}></#if> implements "
                + "Serializable {\n"
                + "<#elseif activeRecord>\n"
                + "public class ${entity} extends Model<${entity}> implements Serializable {\n"
                + "<#elseif entitySerialVersionUID>\n"
                + "public class ${entity} implements Serializable {\n"
                + "<#else>\n"
                + "public class ${entity} {\n"
                + "</#if>\n"
                + "<#if entitySerialVersionUID>\n"
                + "\n"
                + "    private static final long serialVersionUID = 1L;\n"
                + "</#if>\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list table.fields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#-- 主键 -->\n"
                + "        <#if field.keyIdentityFlag>\n"
                + "    @TableId(value = \"${field.annotationColumnName}\", type = IdType.AUTO)\n"
                + "        <#elseif idType??>\n"
                + "    @TableId(value = \"${field.annotationColumnName}\", type = IdType.${idType})\n"
                + "        <#elseif field.convert>\n"
                + "    @TableId(\"${field.annotationColumnName}\")\n"
                + "        </#if>\n"
                + "        <#-- 普通字段 -->\n"
                + "    <#elseif field.fill??>\n"
                + "    <#-- -----   存在字段填充设置   ----->\n"
                + "        <#if field.convert>\n"
                + "    @TableField(value = \"${field.annotationColumnName}\", fill = FieldFill.${field.fill})\n"
                + "        <#else>\n"
                + "    @TableField(fill = FieldFill.${field.fill})\n"
                + "        </#if>\n"
                + "    <#elseif field.convert>\n"
                + "    @TableField(\"${field.annotationColumnName}\")\n"
                + "    </#if>\n"
                + "    <#-- 乐观锁注解 -->\n"
                + "    <#if field.versionField>\n"
                + "    @Version\n"
                + "    </#if>\n"
                + "    <#-- 逻辑删除注解 -->\n"
                + "    <#if field.logicDeleteField>\n"
                + "    @TableLogic\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "\n"
                + "<#if !entityLombokModel>\n"
                + "    <#list table.fields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${entity} set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "\n"
                + "</#if>\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list table.fields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${entity}{\" +\n"
                + "    <#list table.fields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "\n"
                + "</#if>\n"
                + "}"),
        custom_service("custom_service.ftl", "package ${package.Service};\n"
                + "\n"
                + "import ${superServiceClassPackage};\n"
                + "import ${package.Entity}.${entity};\n"
                + "import ${package.Entity}.req.${originEntityName}AddReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}ListReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}UpdateReqVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}DetailRespVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}ListRespVO;\n"
                + "import JustryDeng_Placeholder.PageInfo;\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${briefTableComment} 服务类\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if kotlin>\n"
                + "interface ${table.serviceName} : ${superServiceClass}<${entity}>\n"
                + "<#else>\n"
                + "public interface ${table.serviceName} extends ${superServiceClass}<${entity}> {\n"
                + "\n"
                + "    /**\n"
                + "     * 增\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 新增的数据详情\n"
                + "     */\n"
                + "    ${originEntityName}DetailRespVO add(${originEntityName}AddReqVO req);\n"
                + "\n"
                + "    /**\n"
                + "     * 删\n"
                + "     *\n"
                + "     * @param id\n"
                + "     *         要删除数据的id\n"
                + "     *\n"
                + "     * @return 删除了的数据详情\n"
                + "     */\n"
                + "    ${originEntityName}DetailRespVO delete(<#list customAllFields as field><#if field"
                + ".keyFlag>${field.propertyType}</#if></#list> id);\n"
                + "\n"
                + "    /**\n"
                + "     * 改\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 修改后的数据详情\n"
                + "     */\n"
                + "    ${originEntityName}DetailRespVO update(${originEntityName}UpdateReqVO req);\n"
                + "\n"
                + "    /**\n"
                + "     * 查详情\n"
                + "     *\n"
                + "     * @param id\n"
                + "     *         要查询数据的id\n"
                + "     *\n"
                + "     * @return 数据详情\n"
                + "     */\n"
                + "    ${originEntityName}DetailRespVO detail(<#list customAllFields as field><#if field"
                + ".keyFlag>${field.propertyType}</#if></#list> id);\n"
                + "\n"
                + "    /**\n"
                + "     * 查列表\n"
                + "     *\n"
                + "     * @param req\n"
                + "     *         参数\n"
                + "     *\n"
                + "     * @return 数据列表\n"
                + "     */\n"
                + "    PageInfo<${originEntityName}ListRespVO> list(${originEntityName}ListReqVO req);\n"
                + "}\n"
                + "</#if>\n"),
        custom_serviceImpl("custom_serviceImpl.ftl", "package ${package.ServiceImpl};\n"
                + "\n"
                + "import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;\n"
                + "import com.baomidou.mybatisplus.core.metadata.IPage;\n"
                + "        <#list customAllFields as field>\n"
                + "            <#if field.keyFlag>\n"
                + "        <#-- 自增主键, 不需要导入IdWorker -->\n"
                + "                <#if field.keyIdentityFlag>\n"
                + "                <#else>\n"
                + "        <#-- 其它类型的主键(这里统一认为是雪花算法生成的id) -->\n"
                + "import com.baomidou.mybatisplus.core.toolkit.IdWorker;\n"
                + "                </#if>\n"
                + "            </#if>\n"
                + "        </#list>\n"
                + "import com.baomidou.mybatisplus.extension.plugins.pagination.Page;\n"
                + "import ${superServiceImplClassPackage};\n"
                + "import ${package.Entity}.${entity};\n"
                + "import ${package.Entity}.req.${originEntityName}AddReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}ListReqVO;\n"
                + "import ${package.Entity}.req.${originEntityName}UpdateReqVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}DetailRespVO;\n"
                + "import ${package.Entity}.resp.${originEntityName}ListRespVO;\n"
                + "import ${package.Mapper}.${table.mapperName};\n"
                + "import ${package.Service}.${table.serviceName};\n"
                + "import JustryDeng_Placeholder.PageInfo;\n"
                + "import org.springframework.beans.BeanUtils;\n"
                + "import org.springframework.stereotype.Service;\n"
                + "import org.springframework.transaction.annotation.Transactional;\n"
                + "import org.springframework.util.CollectionUtils;\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "import java.util.Collections;\n"
                + "import java.util.List;\n"
                + "import java.util.Objects;\n"
                + "import java.util.stream.Collectors;\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${briefTableComment} 服务实现类\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "@Service\n"
                + "<#if kotlin>\n"
                + "open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), "
                + "${table.serviceName} {\n"
                + "\n"
                + "}\n"
                + "<#else>\n"
                + "public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, "
                + "${entity}> implements ${table.serviceName} {\n"
                + "\n"
                + "    @Override\n"
                + "    @Transactional(rollbackFor = Exception.class)\n"
                + "    public ${originEntityName}DetailRespVO add(${originEntityName}AddReqVO req) {\n"
                + "        ${entity} po = new ${entity}();\n"
                + "        BeanUtils.copyProperties(req, po);\n"
                + "        <#list customAllFields as field>\n"
                + "            <#if field.propertyType == \"boolean\">\n"
                + "                <#assign getprefix=\"is\"/>\n"
                + "            <#else>\n"
                + "                <#assign getprefix=\"get\"/>\n"
                + "            </#if>\n"
                + "            <#if field.keyFlag>\n"
                + "        <#-- 自增主键 -->\n"
                + "                <#if field.keyIdentityFlag>\n"
                + "        po.set${field.capitalName}(null);\n"
                + "        save(po);\n"
                + "        return detail(po.${getprefix}${field.capitalName}());\n"
                + "                <#else>\n"
                + "        <#-- 其它类型的主键(这里统一认为是雪花算法生成的id) -->\n"
                + "        long id = IdWorker.getId();\n"
                + "        po.set${field.capitalName}(id);\n"
                + "        save(po);\n"
                + "        return detail(id);\n"
                + "                </#if>\n"
                + "            </#if>\n"
                + "        </#list>\n"
                + "    }\n"
                + "    \n"
                + "    @Override\n"
                + "    @Transactional(rollbackFor = Exception.class)\n"
                + "    public ${originEntityName}DetailRespVO delete(<#list customAllFields as field><#if field"
                + ".keyFlag>${field.propertyType}</#if></#list> id) {\n"
                + "        Objects.requireNonNull(id, \"id cannot be null.\");\n"
                + "        ${originEntityName}DetailRespVO resp = detail(id);\n"
                + "        removeById(id);\n"
                + "        return resp;\n"
                + "    }\n"
                + "    \n"
                + "    @Override\n"
                + "    @Transactional(rollbackFor = Exception.class)\n"
                + "    public ${originEntityName}DetailRespVO update(${originEntityName}UpdateReqVO req) {\n"
                + "        <#list customAllFields as field>\n"
                + "            <#if field.keyFlag>\n"
                + "                <#if field.propertyType == \"boolean\">\n"
                + "                    <#assign getprefix=\"is\"/>\n"
                + "                <#else>\n"
                + "                    <#assign getprefix=\"get\"/>\n"
                + "                </#if>\n"
                + "        ${field.propertyType} ${field.propertyName} = req.${getprefix}${field.capitalName}();\n"
                + "            </#if>\n"
                + "        </#list>\n"
                + "        Objects.requireNonNull(id, \"id cannot be null.\");\n"
                + "        // mybatis-plus默认的updateById方法,更新策略默认是NOT_NULL(即更新数据时数据为NULL值时将不更新进数据库)\n"
                + "        ${entity} po = new ${entity}();\n"
                + "        BeanUtils.copyProperties(req, po);\n"
                + "        updateById(po);\n"
                + "        return detail(id);\n"
                + "    }\n"
                + "    \n"
                + "    @Override\n"
                + "    public ${originEntityName}DetailRespVO detail(<#list customAllFields as field><#if field"
                + ".keyFlag>${field.propertyType}</#if></#list> id) {\n"
                + "        Objects.requireNonNull(id, \"id cannot be null.\");\n"
                + "        ${entity} po = getById(id);\n"
                + "        if (po == null) {\n"
                + "            return null;\n"
                + "        }\n"
                + "        ${originEntityName}DetailRespVO resp = new ${originEntityName}DetailRespVO();\n"
                + "        BeanUtils.copyProperties(po, resp);\n"
                + "        return resp;\n"
                + "    }\n"
                + "    \n"
                + "    @Override\n"
                + "    public PageInfo<${originEntityName}ListRespVO> list(${originEntityName}ListReqVO req) {\n"
                + "        int pageNum = req.getPageNum();\n"
                + "        int pageSize = req.getPageSize();\n"
                + "        <#list customAllFields as field>\n"
                + "            <#if field.propertyType == \"boolean\">\n"
                + "                <#assign getprefix=\"is\"/>\n"
                + "            <#else>\n"
                + "                <#assign getprefix=\"get\"/>\n"
                + "            </#if>\n"
                + "        ${field.propertyType} ${field.propertyName} = req.${getprefix}${field.capitalName}();\n"
                + "        </#list>\n"
                + "\n"
                + "        // 分页查\n"
                + "        IPage<${entity}> pageInfo = new Page<>(pageNum, pageSize);\n"
                + "        IPage<${entity}> page = this.baseMapper.selectPage(pageInfo,\n"
                + "                new LambdaQueryWrapper<${entity}>()\n"
                + "        <#list customAllFields as field>\n"
                + "            <#if field.propertyType == \"boolean\">\n"
                + "                <#assign getprefix=\"is\"/>\n"
                + "            <#else>\n"
                + "                <#assign getprefix=\"get\"/>\n"
                + "            </#if>\n"
                + "            .eq(<#if field.propertyType == \"String\">${field.propertyName} != null && ${field"
                + ".propertyName}.trim().length() != 0<#else>${field.propertyName} != null</#if>,  "
                + "${entity}::${getprefix}${field.capitalName}, ${field.propertyName})\n"
                + "        </#list>\n"
                + "            .orderByDesc(${entity}::getId)\n"
                + "        );\n"
                + "        // 转换为resp模型\n"
                + "        List<${entity}> records = page.getRecords();\n"
                + "        List<${originEntityName}ListRespVO> list;\n"
                + "        if (CollectionUtils.isEmpty(records)) {\n"
                + "            list = Collections.emptyList();\n"
                + "        } else {\n"
                + "            list = records.stream().map(po -> {\n"
                + "                ${originEntityName}ListRespVO resp = new ${originEntityName}ListRespVO();\n"
                + "                BeanUtils.copyProperties(po, resp);\n"
                + "                return resp;\n"
                + "            }).collect(Collectors.toList());\n"
                + "        }\n"
                + "        return PageInfo.of(page.getTotal(), pageNum, pageSize, list);\n"
                + "    }\n"
                + "}\n"
                + "</#if>\n"),
        PojoAddReqVO("PojoAddReqVO.ftl", "package ${package.Entity}.req;\n"
                + "\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "import lombok.EqualsAndHashCode;\n"
                + "import JustryDeng_Placeholder.BaseDTO;\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} add req\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "@EqualsAndHashCode(callSuper = true)\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${originEntityName}AddReqVO对象\", description = \"${table.comment!} add req\")\n"
                + "</#if>\n"
                + "public class ${originEntityName}AddReqVO extends BaseDTO {\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list customAllFields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${originEntityName} set${field.capitalName}(${field.propertyType} ${field"
                + ".propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list customAllFields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${originEntityName}{\" +\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "</#if>\n"
                + "}"),
        PojoDetailRespVO("PojoDetailRespVO.ftl", "package ${package.Entity}.resp;\n"
                + "\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} detail resp\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${originEntityName}DetailRespVO对象\", description = \"${table.comment!} detail "
                + "resp\")\n"
                + "</#if>\n"
                + "public class ${originEntityName}DetailRespVO {\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list customAllFields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${originEntityName} set${field.capitalName}(${field.propertyType} ${field"
                + ".propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list customAllFields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${originEntityName}{\" +\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "</#if>\n"
                + "}"),
        PojoListReqVO("PojoListReqVO.ftl", "package ${package.Entity}.req;\n"
                + "\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "import lombok.EqualsAndHashCode;\n"
                + "import JustryDeng_Placeholder.BasePageDTO;\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} list req\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "@EqualsAndHashCode(callSuper = true)\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${originEntityName}ListReqVO对象\", description = \"${table.comment!} list "
                + "req\")\n"
                + "</#if>\n"
                + "public class ${originEntityName}ListReqVO extends BasePageDTO {\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list customAllFields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${originEntityName} set${field.capitalName}(${field.propertyType} ${field"
                + ".propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list customAllFields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${originEntityName}{\" +\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "</#if>\n"
                + "}"),
        PojoListRespVO("PojoListRespVO.ftl", "package ${package.Entity}.resp;\n"
                + "\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} list resp\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${originEntityName}ListRespVO对象\", description = \"${table.comment!} list "
                + "resp\")\n"
                + "</#if>\n"
                + "public class ${originEntityName}ListRespVO {\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list customAllFields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${originEntityName} set${field.capitalName}(${field.propertyType} ${field"
                + ".propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list customAllFields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${originEntityName}{\" +\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "</#if>\n"
                + "}"),
        PojoUpdateReqVO("PojoUpdateReqVO.ftl", "package ${package.Entity}.req;\n"
                + "\n"
                + "<#if swagger>\n"
                + "import io.swagger.annotations.ApiModel;\n"
                + "import io.swagger.annotations.ApiModelProperty;\n"
                + "</#if>\n"
                + "<#if entityLombokModel>\n"
                + "import lombok.Data;\n"
                + "import lombok.EqualsAndHashCode;\n"
                + "import JustryDeng_Placeholder.BaseDTO;\n"
                + "    <#if chainModel>\n"
                + "import lombok.experimental.Accessors;\n"
                + "    </#if>\n"
                + "</#if>\n"
                + "\n"
                + "<#list customImportPackages! as pkg>\n"
                + "import ${pkg};\n"
                + "</#list>\n"
                + "\n"
                + "/**\n"
                + " * <p>\n"
                + " * ${table.comment!} update req\n"
                + " * </p>\n"
                + " *\n"
                + " * @author ${author}\n"
                + " * @since ${date}\n"
                + " */\n"
                + "<#if entityLombokModel>\n"
                + "@Data\n"
                + "    <#if chainModel>\n"
                + "@Accessors(chain = true)\n"
                + "    </#if>\n"
                + "@EqualsAndHashCode(callSuper = true)\n"
                + "</#if>\n"
                + "<#if swagger>\n"
                + "@ApiModel(value = \"${originEntityName}UpdateReqVO对象\", description = \"${table.comment!} update "
                + "req\")\n"
                + "</#if>\n"
                + "public class ${originEntityName}UpdateReqVO extends BaseDTO {\n"
                + "<#-- ----------  BEGIN 字段循环遍历  ---------->\n"
                + "<#list customAllFields as field>\n"
                + "    <#if field.keyFlag>\n"
                + "        <#assign keyPropertyName=\"${field.propertyName}\"/>\n"
                + "    </#if>\n"
                + "\n"
                + "    <#if field.comment!?length gt 0>\n"
                + "        <#if swagger>\n"
                + "    @ApiModelProperty(\"${field.comment}\")\n"
                + "        <#else>\n"
                + "    /**\n"
                + "     * ${field.comment}\n"
                + "     */\n"
                + "        </#if>\n"
                + "    </#if>\n"
                + "    private ${field.propertyType} ${field.propertyName};\n"
                + "</#list>\n"
                + "<#------------  END 字段循环遍历  ---------->\n"
                + "<#if !entityLombokModel>\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field.propertyType == \"boolean\">\n"
                + "            <#assign getprefix=\"is\"/>\n"
                + "        <#else>\n"
                + "            <#assign getprefix=\"get\"/>\n"
                + "        </#if>\n"
                + "    public ${field.propertyType} ${getprefix}${field.capitalName}() {\n"
                + "        return ${field.propertyName};\n"
                + "    }\n"
                + "\n"
                + "    <#if chainModel>\n"
                + "    public ${originEntityName} set${field.capitalName}(${field.propertyType} ${field"
                + ".propertyName}) {\n"
                + "    <#else>\n"
                + "    public void set${field.capitalName}(${field.propertyType} ${field.propertyName}) {\n"
                + "    </#if>\n"
                + "        this.${field.propertyName} = ${field.propertyName};\n"
                + "        <#if chainModel>\n"
                + "        return this;\n"
                + "        </#if>\n"
                + "    }\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "\n"
                + "<#if entityColumnConstant>\n"
                + "    <#list customAllFields as field>\n"
                + "    public static final String ${field.name?upper_case} = \"${field.name}\";\n"
                + "\n"
                + "    </#list>\n"
                + "</#if>\n"
                + "<#if activeRecord>\n"
                + "    @Override\n"
                + "    public Serializable pkVal() {\n"
                + "    <#if keyPropertyName??>\n"
                + "        return this.${keyPropertyName};\n"
                + "    <#else>\n"
                + "        return null;\n"
                + "    </#if>\n"
                + "    }\n"
                + "</#if>\n"
                + "<#if !entityLombokModel>\n"
                + "\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"${originEntityName}{\" +\n"
                + "    <#list customAllFields as field>\n"
                + "        <#if field_index==0>\n"
                + "            \"${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        <#else>\n"
                + "            \", ${field.propertyName}=\" + ${field.propertyName} +\n"
                + "        </#if>\n"
                + "    </#list>\n"
                + "        \"}\";\n"
                + "    }\n"
                + "</#if>\n"
                + "}");
        private final String name;
        private final String content;
        
        JustryDengTemplates(String name, String content) {
            this.name = name;
            this.content = content;
        }
    }
}

相关资料

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
如何使用? 很高兴为您解答这个问题。为了使用MyBatis-Plus自动生成代码模板Controller,您需要遵循以下步骤: 1. 安装MyBatis-Plus插件。您可以在Maven中添加以下代码来添加MyBatis-Plus依赖项: ```xml <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.1</version> </dependency> ``` 2. 根据您的需要配置MyBatis-Plus。您可以在application.properties文件中添加以下配置: ```properties # 数据库连接 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://your-database-url:3306/your-database-name?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC spring.datasource.username=your-database-username spring.datasource.password=your-database-password # MyBatis-Plus配置 mybatis-plus.mapper-locations=classpath:mapper/*.xml mybatis-plus.type-aliases-package=com.example.demo.entity ``` 3. 在您的实体类中添加需要映射的数据库表。对于每个表,需要创建一个Java类,用于映射表中的数据。您可以使用MyBatis-Plus提供的注解来配置主键和字段的映射: ```java @Data @TableName("user") // 表名 public class User { @TableId(value = "id", type = IdType.AUTO) // 主键 private Long id; @TableField("name") // 字段 private String name; // 省略其他字段 } ``` 4. 使用MyBatis-Plus代码生成生成代码MyBatis-Plus提供了一个代码生成器,该生成器可以根据您的实体类和数据库表自动生成代码。您可以使用以下命令启动代码生成器: ```java import com.baomidou.mybatisplus.generator.AutoGenerator; public class CodeGenerator { public static void main(String[] args) { AutoGenerator mpg = new AutoGenerator(); // 定义包名和文件路径 // ... // 配置数据源 // ... // 配置生成策略 // ... // 配置模板 // ... mpg.execute(); } } ``` 5. 完成后,您将在指定的文件夹中看到生成代码,包括实体类、Mapper接口、XML文件和Service类。 希望这能帮到您!如果您有任何其他问题,请随时问我。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值