3. Springboot+mybatisplus Integrated-------Code generator

Source: Internet
Author: User

1 <Dependency>2     <groupId>Org.projectlombok</groupId>3     <Artifactid>Lombok</Artifactid>4     <version>1.18.0</version>5     <Scope>Provided</Scope>6 </Dependency>7 <!--add a dependency on the code generator -8 <Dependency>9     <groupId>Org.apache.velocity</groupId>Ten     <Artifactid>Velocity-engine-core</Artifactid> One     <version>2.0</version> A </Dependency>

Development tools: STS code Download Link: GitHub Admin code version: Springboot:1.5.14.release

    Using more than 2.0 of Springboot, some exceptions will be reported. Welcome to know the reason why the Daniel doubts.

mybatisplus:2.3 generation rules refer to: Generation rules preface:

I have used the most convenient code generator, and the function is really powerful!

Build code generator: 1. Add dependency: (1) Code generator dependent (2) Lombok dependent

Using Lombok can reduce the development of code

1          <Dependency>2             <groupId>Org.projectlombok</groupId>3             <Artifactid>Lombok</Artifactid>4             <version>1.18.0</version>5             <Scope>Provided</Scope>6         </Dependency>7         <!--add a dependency on the code generator -8         <Dependency>9             <groupId>Org.apache.velocity</groupId>Ten             <Artifactid>Velocity-engine-core</Artifactid> One             <version>2.0</version> A         </Dependency>                

2. Write the generator:
1  Packagecom.xm;2 3 Importorg.junit.Test;4 5 ImportCom.baomidou.mybatisplus.enums.IdType;6 ImportCom.baomidou.mybatisplus.generator.AutoGenerator;7 ImportCom.baomidou.mybatisplus.generator.config.DataSourceConfig;8 ImportCom.baomidou.mybatisplus.generator.config.GlobalConfig;9 ImportCom.baomidou.mybatisplus.generator.config.PackageConfig;Ten ImportCom.baomidou.mybatisplus.generator.config.StrategyConfig; One ImportCom.baomidou.mybatisplus.generator.config.rules.DbType; A ImportCom.baomidou.mybatisplus.generator.config.rules.NamingStrategy; -  -  Public classMpgenerator { the      - @Test -      Public voidCreate () { -          +String tableName = "User"; -          +         /** A * Configuration: at * 1. Global configuration - * 2. Data Source Configuration - * 3. Policy configuration - * 4. Package name policy configuration - * 5. Integrated configuration -          */ in          -         //1. Global Configuration toGlobalConfig GlobalConfig =NewGlobalConfig (); + GlobalConfig -               //To set the code generation path the. Setoutputdir ("F:\\xm\\springboot\\springboot_mybatisplus\\src\\main\\java") *                //Set Author $. Setauthor ("XM")Panax Notoginseng                //set the opening and closing of level two cache -. Setenablecache (false) the                //Set database ID self-increment + . Setidtype (Idtype.auto) A                //Setting Overwrite Updates the. Setfileoverride (true) +                //Set Go I -. Setservicename ("%sservice") $                //set up a production result mapping map $. Setbaseresultmap (true); -          -         //2. Data Source Configuration theDatasourceconfig Datasourceconfig =Newdatasourceconfig (); - DatasourceconfigWuyi                    //Setting the database type the . Setdbtype (dbtype.mysql) -. SetUrl ("Jdbc:mysql://10.1.51.31:3306/xm?usessl=true") Wu. setusername ("root") -. SetPassword ("cube1501") About. Setdrivername ("Com.mysql.jdbc.Driver"); $         -        //3. Policy configuration -Strategyconfig Strategyconfig =Newstrategyconfig (); - Strategyconfig A                //turn on global capitalization naming +. Setcapitalmode (true) the                //turn on underline conversion -. Setdbcolumnunderline (true) $                //Open Hump naming the . setnaming (Namingstrategy.underline_to_camel) the. Setentitylombokmodel (true) the . Setinclude (tableName); the         -        //4. Package Name policy configuration inPackageconfig Packageconfig =Newpackageconfig (); the Packageconfig the. SetParent ("Com.xm") About. Setcontroller ("Controller") the. Setentity ("Pojo") the. Setmapper ("Mapper") the. Setservice ("service") +. Setserviceimpl ("Service.impl") -. Setxml ("Mapper.xml"); the        Bayi        //5. Integrated configuration theAutogenerator Autogenerator =Newautogenerator (); the Autogenerator - . Setglobalconfig (GlobalConfig) - . Setdatasource (datasourceconfig) the . Setstrategy (strategyconfig) the . Setpackageinfo (packageconfig); the         the Autogenerator.execute (); -          the     } the  the}

3. Test run:

                                           2018-07-19

3. Springboot+mybatisplus Integrated-------Code generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.