#mybatis-plus使用generator代码生成器生成实体类支持Swagger2

mybatis-plus使用generator代码生成器生成实体类支持Swagger2

  • 1.先搭建项目,引入maven依赖
  • 2.编写代码生成器代码(有说明)
  • 3.在resources目录下创建templates目录
  • 4.在templates目录下创建entity.java.vm模板(代码如下)
  • 5.基本完成只要运行代码生成器代码,输入表名即可

使用自定义模板生成支持Swagger2的实体类,生成的@ApiModelProperty中的value值都是数据库表字段的注释,所有生成之前数据表一定要先注释好

1.先搭建项目,引入maven依赖



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.3.RELEASE
         
    
    com.emep.mall
    admin
    0.0.1-SNAPSHOT
    admin
    Demo project for Spring Boot

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            com.github.flying-cattle
            mybatis-dsc-generator
            3.0.0.RELEASE
        

        
        
            mysql
            mysql-connector-java
            runtime
        
        
        
            org.projectlombok
            lombok
            true
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            3.2.0
        
        
        
            com.baomidou
            mybatis-plus-generator
            3.2.0
        
        
        
            org.freemarker
            freemarker
            2.3.28
        
        
        
            org.apache.velocity
            velocity-engine-core
            2.1
        
        
        
            io.springfox
            springfox-swagger2
            2.9.2
        
        
        
            com.alibaba
            fastjson
            1.2.47
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



maven.xml

2.编写代码生成器代码(有说明)

package com.emep.mall.admin.generator;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
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.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @ClassName: CodeGenerator
 * @Description:https://blog.csdn.net/sj13074480550/article/details/102976146
 * @Author: BYP <[email protected]>
 * @Date: 2020/9/25  23:25
 * @Copyright: 2019 www.tydic.com Inc. All rights reserved.
 * 注意:本内容仅限于弘毅天承信息技术股份有限公司内部传阅,禁止外泄以及用于其他的商业目
 */
public class CodeGenerator {

    /**
     * 

* 读取控制台内容 *

*/ public static String scanner(String tip) { Scanner scanner = new Scanner(System.in); StringBuilder help = new StringBuilder(); help.append("请输入" + tip + ":"); System.out.println(help.toString()); if (scanner.hasNext()) { String ipt = scanner.next(); if (StringUtils.isNotEmpty(ipt)) { return ipt; } } throw new MybatisPlusException("请输入正确的" + tip + "!"); } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); AutoGenerator generator = new AutoGenerator(); // 全局变量配置 GlobalConfig gc = new GlobalConfig(); String projectPath = System.getProperty("user.dir"); //当前项目 gc.setOutputDir(projectPath+"/src/main/java"); // 输出路径 gc.setFileOverride(true); // 默认 false ,是否覆盖已生成文件 gc.setOpen(false); //默认true ,是否打开输出目录 gc.setEnableCache(false); // 默认false,是否开启二级缓存 gc.setAuthor("byp"); // 作者 gc.setSwagger2(true); //默认false gc.setBaseResultMap(true); // 默认false gc.setDateType(DateType.TIME_PACK); // 时间策略 默认TIME_PACK gc.setBaseColumnList(true); //默认false 和basemodel相似 gc.setEntityName("%s"); gc.setControllerName("%sController"); gc.setServiceName("I%sService"); gc.setServiceImplName("%sServiceImpl"); gc.setMapperName("I%sMapper"); gc.setXmlName("%sMapper"); gc.setIdType(IdType.AUTO); // 指定生成的主键类型 generator.setGlobalConfig(gc); // 数据源配置 DataSourceConfig dc = new DataSourceConfig(); dc.setDbQuery(new MySqlQuery()); // 数据库信息查询 //默认mysql dc.setDbType(DbType.MYSQL);// 数据库类型 dc.setTypeConvert(new MySqlTypeConvert()); //类型转换 默认mysql dc.setUrl("jdbc:mysql://127.0.0.1:3306/buybit_wallet_sign?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&failOverReadOnly=false&useSSL=true&serverTimezone=UTC"); dc.setDriverName("com.mysql.cj.jdbc.Driver"); dc.setUsername("root"); dc.setPassword("root"); generator.setDataSource(dc); // 包配置 PackageConfig pc = new PackageConfig(); pc.setParent("com.emep.mall.admin.code");//代码生成到哪个包下面 // pc.setModuleName(""); //此处是所属模块名称 // pc.setEntity("entity"); //默认entity,controller,service,service.impl,mapper,mapper.xml generator.setPackageInfo(pc); // 自定义配置 InjectionConfig cfg = new InjectionConfig() { @Override public void initMap() { // to do nothing } }; /** * 将xml生成到resource下面 */ String templatePath = "/templates/mapper.xml.vm"; // Velocity模板 // 自定义输出配置 List focList = new ArrayList<>(); // 自定义配置会被优先输出 focList.add(new FileOutConfig(templatePath) { @Override public String outputFile(TableInfo tableInfo) { // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!! return projectPath + "/src/main/resources/mapper/" // + pc.getModuleName() + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML; } }); cfg.setFileOutConfigList(focList); generator.setCfg(cfg); // 配置模板 TemplateConfig tc = new TemplateConfig(); // templates/entity.java 模板路径配置,默认在templates目录下,.vm 后缀不用加 tc.setEntity("templates/entity.java");//使用自定义模板生成实体类 tc.setXml(""); generator.setTemplate(tc); // 数据库表配置 StrategyConfig sc = new StrategyConfig(); sc.setCapitalMode(false); //是否大写命名 默认false sc.setSkipView(true); //是否跳过试图 默认false sc.setNaming(NamingStrategy.underline_to_camel);// 表映射 驼峰命名 sc.setColumnNaming(NamingStrategy.underline_to_camel); // 字段映射 驼峰 sc.setEntityLombokModel(true); //是否使用lombak 默认为false sc.setRestControllerStyle(true); // 默认false sc.setEntitySerialVersionUID(true); //默认true sc.setEntityColumnConstant(true); //默认false 将mysql字段名生成静态变量 sc.setInclude(scanner("表名,多个英文逗号分割").split(",")); //表名,用,隔开 需要生产 // sc.setExclude(""); // 不需要生成 二选一 sc.setEntityTableFieldAnnotationEnable(true); // 默认false 注释 sc.setControllerMappingHyphenStyle(false); //默认false sc.setLogicDeleteFieldName("status"); // 逻辑删除字段名称 generator.setStrategy(sc); // 模板引擎 generator.setTemplateEngine(new VelocityTemplateEngine()); generator.execute(); } }
generator生成代码

3.在resources目录下创建templates目录

4.在templates目录下创建entity.java.vm模板(代码如下)

package ${package.Entity};

#foreach($pkg in ${table.importPackages})
import ${pkg};
#end
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
#if(${entityLombokModel})
import lombok.Data;
import lombok.EqualsAndHashCode;
    ##import lombok.experimental.Accessors;
#end

/**
 * @Description:$!{table.comment}
 * @author ${author}
 * @since ${date}
 */
@ApiModel(value ="$!{table.comment}")
#if(${entityLombokModel})
@Data
    #if(${superEntityClass})
    @EqualsAndHashCode(callSuper = true)
    #else
    @EqualsAndHashCode(callSuper = false)
    #end
    ##@Accessors(chain = true)
#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

private static final long serialVersionUID = 1L;

## ----------  BEGIN 字段循环遍历  ----------
#foreach($field in ${table.fields})
    #if(${field.keyFlag})
        #set($keyPropertyName=${field.propertyName})
    #end
    #if("$!field.comment" != "")
    @ApiModelProperty(value = "${field.comment}")
    #end
    #if(${field.keyFlag})
        ## 主键s
        #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})
    @TableField("${field.name}")
    #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($!{velocityCount}==1)
                "${field.propertyName}=" + ${field.propertyName} +
        #else
                ", ${field.propertyName}=" + ${field.propertyName} +
        #end
    #end
        "}";
        }
#end
        }
自定义生成代码逻辑

5.基本完成只要运行代码生成器代码,输入表名即可

"D:\Program Files\Java\jdk1.8.0_45\bin\java.exe" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3\lib\idea_rt.jar=51113:D:\Program Files\JetBrains\IntelliJ IDEA 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\Java\jdk1.8.0_45\jre\lib\charsets.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\deploy.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\access-bridge-64.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\cldrdata.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\dnsns.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\jaccess.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\jfxrt.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\localedata.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\nashorn.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunec.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunjce_provider.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunmscapi.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\sunpkcs11.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\ext\zipfs.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\javaws.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\jce.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\jfr.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\jfxswt.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\jsse.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\management-agent.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\plugin.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\resources.jar;D:\Program Files\Java\jdk1.8.0_45\jre\lib\rt.jar;D:\software\workspace\idea\admin\target\classes;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter-web\2.3.3.RELEASE\spring-boot-starter-web-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter\2.3.3.RELEASE\spring-boot-starter-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot\2.3.3.RELEASE\spring-boot-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter-logging\2.3.3.RELEASE\spring-boot-starter-logging-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;D:\software\Repository\mavenRepository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;D:\software\Repository\mavenRepository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;D:\software\Repository\mavenRepository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;D:\software\Repository\mavenRepository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;D:\software\Repository\mavenRepository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\software\Repository\mavenRepository\org\yaml\snakeyaml\1.26\snakeyaml-1.26.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter-json\2.3.3.RELEASE\spring-boot-starter-json-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\core\jackson-databind\2.11.2\jackson-databind-2.11.2.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\core\jackson-core\2.11.2\jackson-core-2.11.2.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.2\jackson-datatype-jdk8-2.11.2.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.2\jackson-datatype-jsr310-2.11.2.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.2\jackson-module-parameter-names-2.11.2.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter-tomcat\2.3.3.RELEASE\spring-boot-starter-tomcat-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\org\apache\tomcat\embed\tomcat-embed-core\9.0.37\tomcat-embed-core-9.0.37.jar;D:\software\Repository\mavenRepository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;D:\software\Repository\mavenRepository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.37\tomcat-embed-websocket-9.0.37.jar;D:\software\Repository\mavenRepository\org\springframework\spring-web\5.2.8.RELEASE\spring-web-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-beans\5.2.8.RELEASE\spring-beans-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-webmvc\5.2.8.RELEASE\spring-webmvc-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-aop\5.2.8.RELEASE\spring-aop-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-context\5.2.8.RELEASE\spring-context-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-expression\5.2.8.RELEASE\spring-expression-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\com\github\flying-cattle\mybatis-dsc-generator\3.0.0.RELEASE\mybatis-dsc-generator-3.0.0.RELEASE.jar;D:\software\Repository\mavenRepository\com\alibaba\druid\1.1.16\druid-1.1.16.jar;D:\software\Repository\mavenRepository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;D:\software\Repository\mavenRepository\mysql\mysql-connector-java\8.0.21\mysql-connector-java-8.0.21.jar;D:\software\Repository\mavenRepository\org\projectlombok\lombok\1.18.12\lombok-1.18.12.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus-boot-starter\3.2.0\mybatis-plus-boot-starter-3.2.0.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus\3.2.0\mybatis-plus-3.2.0.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-autoconfigure\2.3.3.RELEASE\spring-boot-autoconfigure-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\boot\spring-boot-starter-jdbc\2.3.3.RELEASE\spring-boot-starter-jdbc-2.3.3.RELEASE.jar;D:\software\Repository\mavenRepository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;D:\software\Repository\mavenRepository\org\springframework\spring-jdbc\5.2.8.RELEASE\spring-jdbc-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-tx\5.2.8.RELEASE\spring-tx-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus-generator\3.2.0\mybatis-plus-generator-3.2.0.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus-extension\3.2.0\mybatis-plus-extension-3.2.0.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus-core\3.2.0\mybatis-plus-core-3.2.0.jar;D:\software\Repository\mavenRepository\com\baomidou\mybatis-plus-annotation\3.2.0\mybatis-plus-annotation-3.2.0.jar;D:\software\Repository\mavenRepository\com\github\jsqlparser\jsqlparser\2.1\jsqlparser-2.1.jar;D:\software\Repository\mavenRepository\org\mybatis\mybatis\3.5.2\mybatis-3.5.2.jar;D:\software\Repository\mavenRepository\org\mybatis\mybatis-spring\2.0.2\mybatis-spring-2.0.2.jar;D:\software\Repository\mavenRepository\org\freemarker\freemarker\2.3.28\freemarker-2.3.28.jar;D:\software\Repository\mavenRepository\org\apache\velocity\velocity-engine-core\2.1\velocity-engine-core-2.1.jar;D:\software\Repository\mavenRepository\org\apache\commons\commons-lang3\3.10\commons-lang3-3.10.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-swagger2\2.9.2\springfox-swagger2-2.9.2.jar;D:\software\Repository\mavenRepository\io\swagger\swagger-annotations\1.5.20\swagger-annotations-1.5.20.jar;D:\software\Repository\mavenRepository\io\swagger\swagger-models\1.5.20\swagger-models-1.5.20.jar;D:\software\Repository\mavenRepository\com\fasterxml\jackson\core\jackson-annotations\2.11.2\jackson-annotations-2.11.2.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-spi\2.9.2\springfox-spi-2.9.2.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-core\2.9.2\springfox-core-2.9.2.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-schema\2.9.2\springfox-schema-2.9.2.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-swagger-common\2.9.2\springfox-swagger-common-2.9.2.jar;D:\software\Repository\mavenRepository\io\springfox\springfox-spring-web\2.9.2\springfox-spring-web-2.9.2.jar;D:\software\Repository\mavenRepository\com\google\guava\guava\20.0\guava-20.0.jar;D:\software\Repository\mavenRepository\com\fasterxml\classmate\1.5.1\classmate-1.5.1.jar;D:\software\Repository\mavenRepository\org\springframework\plugin\spring-plugin-core\1.2.0.RELEASE\spring-plugin-core-1.2.0.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\plugin\spring-plugin-metadata\1.2.0.RELEASE\spring-plugin-metadata-1.2.0.RELEASE.jar;D:\software\Repository\mavenRepository\org\mapstruct\mapstruct\1.2.0.Final\mapstruct-1.2.0.Final.jar;D:\software\Repository\mavenRepository\com\alibaba\fastjson\1.2.47\fastjson-1.2.47.jar;D:\software\Repository\mavenRepository\net\bytebuddy\byte-buddy\1.10.14\byte-buddy-1.10.14.jar;D:\software\Repository\mavenRepository\org\springframework\spring-core\5.2.8.RELEASE\spring-core-5.2.8.RELEASE.jar;D:\software\Repository\mavenRepository\org\springframework\spring-jcl\5.2.8.RELEASE\spring-jcl-5.2.8.RELEASE.jar" com.emep.mall.admin.generator.CodeGenerator
请输入表名,多个英文逗号分割:
user
23:35:19.425 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================准备生成文件...==========================
23:35:21.070 [main] WARN org.apache.velocity.deprecation - configuration key 'file.resource.loader.unicode' has been deprecated in favor of 'resource.loader.file.unicode'
23:35:21.072 [main] WARN org.apache.velocity.deprecation - configuration key 'file.resource.loader.path' has been deprecated in favor of 'resource.loader.file.path'
23:35:21.073 [main] WARN org.apache.velocity.deprecation - configuration key 'file.resource.loader.class' has been deprecated in favor of 'resource.loader.file.class'
23:35:21.073 [main] WARN org.apache.velocity.deprecation - configuration key 'input.encoding' has been deprecated in favor of 'resource.default_encoding'
23:35:21.078 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 创建目录: [D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\entity]
23:35:21.080 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 创建目录: [D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\controller]
23:35:21.090 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 创建目录: [D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\service]
23:35:21.091 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 创建目录: [D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\mapper]
23:35:21.091 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 创建目录: [D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\service\impl]
23:35:21.093 [main] DEBUG org.apache.velocity - Initializing Velocity, Calling init()...
23:35:21.093 [main] DEBUG org.apache.velocity - Starting Apache Velocity v2.0
23:35:21.096 [main] DEBUG org.apache.velocity - Default Properties resource: org/apache/velocity/runtime/defaults/velocity.properties
23:35:21.103 [main] DEBUG org.apache.velocity - ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.105 [main] DEBUG org.apache.velocity - initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
23:35:21.107 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Stop
23:35:21.108 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Define
23:35:21.108 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Break
23:35:21.109 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
23:35:21.110 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Macro
23:35:21.112 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Parse
23:35:21.113 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Include
23:35:21.114 [main] DEBUG org.apache.velocity - Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
23:35:21.141 [main] DEBUG org.apache.velocity.parser - Created '20' parsers.
23:35:21.160 [main] DEBUG org.apache.velocity.macro - "velocimacro.library.path" is not set. Trying default library: velocimacros.vtl
23:35:21.161 [main] DEBUG org.apache.velocity.loader.file - Could not load resource 'velocimacros.vtl' from ResourceLoader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.161 [main] DEBUG org.apache.velocity.macro - Default library velocimacros.vtl not found. Trying old default library: VM_global_library.vm
23:35:21.161 [main] DEBUG org.apache.velocity.loader.file - Could not load resource 'VM_global_library.vm' from ResourceLoader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.161 [main] DEBUG org.apache.velocity.macro - Old default library VM_global_library.vm not found.
23:35:21.162 [main] DEBUG org.apache.velocity.macro - allowInline = true: VMs can be defined inline in templates
23:35:21.162 [main] DEBUG org.apache.velocity.macro - allowInlineToOverride = false: VMs defined inline may NOT replace previous VM definitions
23:35:21.162 [main] DEBUG org.apache.velocity.macro - allowInlineLocal = false: VMs defined inline will be global in scope if allowed.
23:35:21.162 [main] DEBUG org.apache.velocity.macro - autoload off: VM system will not automatically reload global library macros
23:35:21.182 [main] DEBUG org.apache.velocity.loader - ResourceManager: found /templates/mapper.xml.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.198 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/mapper.xml.vm;  文件:D:\software\workspace\idea\admin/src/main/resources/mapper//UserMapper.xml
23:35:21.218 [main] DEBUG org.apache.velocity.loader - ResourceManager: found templates/entity.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.229 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:templates/entity.java.vm;  文件:D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\entity\User.java
23:35:21.231 [main] DEBUG org.apache.velocity.loader - ResourceManager: found /templates/mapper.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.233 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/mapper.java.vm;  文件:D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\mapper\IUserMapper.java
23:35:21.235 [main] DEBUG org.apache.velocity.loader - ResourceManager: found /templates/service.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.236 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/service.java.vm;  文件:D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\service\IUserService.java
23:35:21.238 [main] DEBUG org.apache.velocity.loader - ResourceManager: found /templates/serviceImpl.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.239 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/serviceImpl.java.vm;  文件:D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\service\impl\UserServiceImpl.java
23:35:21.243 [main] DEBUG org.apache.velocity.loader - ResourceManager: found /templates/controller.java.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
23:35:21.244 [main] DEBUG com.baomidou.mybatisplus.generator.engine.AbstractTemplateEngine - 模板:/templates/controller.java.vm;  文件:D:\software\workspace\idea\admin/src/main/java\com\emep\mall\admin\code\controller\UserController.java
23:35:21.244 [main] DEBUG com.baomidou.mybatisplus.generator.AutoGenerator - ==========================文件生成完成!!!==========================

Process finished with exit code 0

控制台输出信息

6.生成的实体类效果如下:

package com.emep.mall.admin.code.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
    
/**
 * @Description:
 * @author byp
 * @since 2020-09-25
 */
@ApiModel(value ="")
@Data
    @EqualsAndHashCode(callSuper = false)
    @TableName("user")
public class User implements Serializable {

private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "ID")
                @TableId(value = "id", type = IdType.AUTO)
                private Long id;
    @ApiModelProperty(value = "登录名")
    @TableField("login_name")
        private String loginName;
    @ApiModelProperty(value = "秘密")
    @TableField("password")
        private String password;
    @ApiModelProperty(value = "昵称")
    @TableField("nickname")
        private String nickname;
    @ApiModelProperty(value = "类型")
    @TableField("type")
        private Integer type;
    @ApiModelProperty(value = "状态:-1失败,0等待,1成功")
    @TableField("state")
        private Integer state;
    @ApiModelProperty(value = "备注")
    @TableField("note")
        private String note;
    @ApiModelProperty(value = "创建时间")
    @TableField("create_time")
        private LocalDateTime createTime;
    @ApiModelProperty(value = "更新时间")
    @TableField("update_time")
        private LocalDateTime updateTime;
    @ApiModelProperty(value = "修改人用户ID")
    @TableField("update_uid")
        private Long updateUid;
    @ApiModelProperty(value = "登录IP地址")
    @TableField("login_ip")
        private String loginIp;
    @ApiModelProperty(value = "登录地址")
    @TableField("login_addr")
        private String loginAddr;


    public static final String ID = "id";

    public static final String LOGIN_NAME = "login_name";

    public static final String PASSWORD = "password";

    public static final String NICKNAME = "nickname";

    public static final String TYPE = "type";

    public static final String STATE = "state";

    public static final String NOTE = "note";

    public static final String CREATE_TIME = "create_time";

    public static final String UPDATE_TIME = "update_time";

    public static final String UPDATE_UID = "update_uid";

    public static final String LOGIN_IP = "login_ip";

    public static final String LOGIN_ADDR = "login_addr";

        }
5.jpg

7.生成的controller类效果如下:

package com.emep.mall.admin.code.controller;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * 

* 前端控制器 *

* * @author byp * @since 2020-09-25 */ @RestController @RequestMapping("/user") public class UserController { }
6.jpg

8.生成的service类效果如下:

package com.emep.mall.admin.code.service;

import com.emep.mall.admin.code.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;

/**
 * 

* 服务类 *

* * @author byp * @since 2020-09-25 */ public interface IUserService extends IService { }
7.jpg

9.生成的service实现类效果如下:

package com.emep.mall.admin.code.service.impl;

import com.emep.mall.admin.code.entity.User;
import com.emep.mall.admin.code.mapper.IUserMapper;
import com.emep.mall.admin.code.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * 

* 服务实现类 *

* * @author byp * @since 2020-09-25 */ @Service public class UserServiceImpl extends ServiceImpl implements IUserService { }
8.jpg

10.生成的接口实现类效果如下:

package com.emep.mall.admin.code.mapper;

import com.emep.mall.admin.code.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * 

* Mapper 接口 *

* * @author byp * @since 2020-09-25 */ public interface IUserMapper extends BaseMapper { }
9.jpg

11.生成的接口XML实现类效果如下:





    
        
        
        
        
        
        
        
        
        
        
        
        
    
    
        id, login_name, password, nickname, type, state, note, create_time, update_time, update_uid, login_ip, login_addr
    
    

10.jpg

你可能感兴趣的:(#mybatis-plus使用generator代码生成器生成实体类支持Swagger2)