MyBatis-Plus-Generator Configuration

This article only using MyBatis-Plus code generator configured to do save for the plug-in shoes used for reference.
There are a lot of internal default configuration, you can have sexual interest in children's shoes under research source.
ps: official documents more complete http://mp.baomidou.com/

package com.kichun.ucenter.service;

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.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
importcom.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; 

Import java.io.File;
 Import Classes in java.util *. ; 

/ ** 
 . * the Created by wangqichang ON 2018/6/1 
 * / 
public  class MabatisPlusGenerator { 

    // makefile where the project path 
    Private  static String baseProjectPath = "D: \\ \\ strandrd_official_website Git kichun \\ \\ \\ kichun-ucenter kichun-ucenter-the Entity" ; 

    // basic package name 
    Private  static String basePackage = "com.kichun.ucenter " ;
     // author 
    Private  static String authorName =" wangqichang " ;
     //To generate a table name 
    private  static String [] = {Tables "t_role", "t_resource", "t_role_resource", "t_user_role" };
     // Table prefix 
    private  static String prefix = "T_" ; 

    // database four elements arranged 
    private  static String driverName = "net.sf.log4jdbc.DriverSpy" ;
     Private  static String url = "jdbc: log4jdbc: MySQL: //127.0.0.1: 3306 / = to true kichun_dev useUnicode & characterEncoding = utf8 & zeroDateTimeBehavior = = convertToNull & allowMultiQueries to true?" ;
     Private  static String username = "do not tell you" ;
    Private  static String password = "password does not tell you" ;


    public  static  void main (String [] args) { 


        AutoGenerator Gen = new new AutoGenerator (); 

        / ** 
         * Database Configuration 
         * / 
        gen.setDataSource ( new new DataSourceConfig () 
                .setDbType (DbType.MYSQL) 
                .setDriverName (driverName) 
                .setUrl ( URL) 
                .setUsername (username) 
                .setPassword (password) 
                .setTypeConvert ( new new MySqlTypeConvert () {
                     // custom type conversion table column [optionally] 
                    @Override
                     public DbColumnType processTypeConvert(String fieldType) {
                        System.out.println("转换类型:" + fieldType);
                        // if ( fieldType.toLowerCase().contains( "tinyint" ) ) {
                        //    return DbColumnType.BOOLEAN;
                        // }
                        return super.processTypeConvert(fieldType);
                    }
                }));

        /**
         * 全局配置
         */
        gen.setGlobalConfig(new GlobalConfig()
                .setOutputDir( baseProjectPath + "/src/main/java")//输出目录
                .setFileOverride ( to true ) // whether to overwrite files 
                .setActiveRecord ( to true ) // open activeRecord mode 
                .setEnableCache ( false ) // XML secondary cache 
                .setBaseResultMap ( to true ) // XML about ResultMaps is 
                .setBaseColumnList ( to true ) // XML columList 
                . the setOpen ( to false ) // after generating the open folder 
                .setAuthor (the authorName)
                 // custom file name,% s attention entity attribute table is automatically populated!
                .setMapperName ( "% sMapper" ) 
                .setXmlName ( "% sMapper" ) 
                .setServiceName ( "% Sservice" ) 
                .setServiceImplName ( "% sServiceImpl" ) 
                .setControllerName ( "% sController" ) 
        ); 

        / ** 
         * policy configuration 
         * / 
        gen.setStrategy ( new new StrategyConfig ()
                 // .setCapitalMode (to true) // global capital named
                 // .setDbColumnUnderline (to true) // global underlined name 
                .setTablePrefix(newString [] {prefix}) // Here you can modify your table prefix 
                .setNaming (NamingStrategy.underline_to_camel) // table generation strategy 
                .setInclude (the Tables) // need to generate tables 
                .setRestControllerStyle ( to true )
                 // . setExclude (new new String [] { "Test"}) // excluded generated table
                 // custom entity parent
                 // .setSuperEntityClass ( "com.baomidou.demo.TestEntity")
                 // custom entity, public fields
                 // .setSuperEntityColumns (new new String [] { "test_id"})
                 // .setTableFillList (tableFillList)
                // custom mapper superclass default BaseMapper
                 // .setSuperMapperClass ( "com.baomidou.mybatisplus.mapper.BaseMapper")
                 // custom service superclass default IService
                 // .setSuperServiceClass ( "com.baomidou.demo.TestService")
                 // custom service implementation class parent class default ServiceImpl
                 // .setSuperServiceImplClass ( "com.baomidou.demo.TestServiceImpl")
                 // custom controller superclass
                 // .setSuperControllerClass ( "com.kichun." packageName + +. "controller. AbstractController ")
                 // [entity] whether to generate a constant field (default false)
                 //Final static String ID = public "test_id";
                 // .setEntityColumnConstant (to true)
                 // [] whether the entity model builder (defaults to false)
                 // public the setName the User (String name) {name = this.name; return the this; }
                 // .setEntityBuilderModel (to true)
                 // [entity] whether lombok model (default false) <a href=" "> https://projectlombok.org/ the Document </a> 
                .setEntityLombokModel ( to true )
                 // Boolean type whether to remove the prefix field is processed
                 // .setEntityBooleanColumnRemoveIsPrefix (to true)
                 //.setRestControllerStyle (to true)
                 // .setControllerMappingHyphenStyle (to true) 
        ); 

        / ** 
         * package configuration 
         * / 
        gen.setPackageInfo ( new new PackageConfig ()
                         // .setModuleName ( "the User") 
                        .setParent (basePackage) // custom package path 
                        .setController ( "the controller") // here is the controller package name, the default Web 
                        .setEntity ( "the Entity" ) 
                        .setMapper ( "DAO" ) 
                        .setService ( "Service" ) 
                        .setServiceImpl("service.impl" ) 
                        .setXml ( "Mapper" ) 
                        ); 

        / ** 
         * injection custom configuration 
         * / 
        // injection custom configurations may be used in a VM set cfg.abc value 
        InjectionConfig ABC = new new InjectionConfig () { 
            @Override 
            public  void initMap () { 
                the Map <String, Object> = Map new new the HashMap <> (); 
                map.put ( "ABC", the this .getConfig () getGlobalConfig () the getAuthor () + "-mp.". );
                 the this.setMap (Map); 
            } 
        }; 
        // custom file output location (optional) 
        List <FileOutConfig> = fileOutList new new the ArrayList <> (); 
        fileOutList.add ( new new FileOutConfig ( "/ Templates / mapper.xml.ftl" ) { 
            @Override 
            public String the outputFile (the TableInfo TableInfo) {
                 return baseProjectPath + "/ the src / main / Resources / by mappers /" + tableInfo.getEntityName () + ".xml" ; 
            } 
        }); 
        abc.setFileOutConfigList (fileOutList); 
        Gen .setCfg (abc); 

        / ** 
         * Specifies the default template engine is VelocityTemplateEngine, dependent on the need to introduce the relevant engine
          * / 
        gen.setTemplateEngine ( new newFreemarkerTemplateEngine ()); 

        / ** 
         * Template Configuration 
         * / 
        gen.setTemplate ( 
                // Close generating default xml, adjusted to the root directory generates 
                new new TemplateConfig () setXml (. Null )
                 // custom configuration template, the template may refer to the source / mybatis-plus / src / main / resources / template using the Copy
                 // to your project src / main / resources / directory under the template, the template name can also be custom configured as follows:
                 // .setController ( "...");
                 / / .setEntity ( "...");
                 // .setMapper ( "...");
                 // .setXml ( "...");
                 //.setService ( "...");
                 //.setServiceImpl ( "..."); 
        ); 

        // perform generation 
        gen.execute (); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/huangjinyong/p/11234268.html