Automatic production using Mybatis-generator in Springboot

Source: Internet
Author: User


1. Add plug-in configuration in Pom.xml

<plugin> <groupId>org.mybatis.generator</groupId> <artifactid>mybati S-generator-maven-plugin</artifactid> <version>1.3.5</version> <depende                        ncies> <dependency> <groupId> mysql</groupid> <artifactId> mysql-connector-java</artifactid> <version> 5.1.39</ver sion> </dependency> <dependency> &LT;GROUPID&G                         T;org.mybatis.generator</groupid> <artifactId>mybatis-generator-core</artifactId> <version>1.3.5</version> </dependency> </de pendencies> <executions> <execution> <id>gen Erate MyBatis artifacts&Lt;/id> <phase>  Package</phase> <goals> <goal>generate</goal> </goals> </execution> </executions> <c Onfiguration> <!--allow mobile generated files--<verbose>true</verbose> <!--is covered--<overwrite>true</overwrite> <!--Auto-generated configuration-<configurationFile>src/main/resources/mybatis-generator.xml</configurationfile> </configuration> </plug In>

2. Add Mybatis-generator.xml to the Resources folder

<?xml version= "1.0" encoding= "UTF-8"? ><!DOCTYPE generatorconfiguration Public"-// mybatis Generator Configuration 1.0//en" "Http:// DTD "><generatorConfiguration> <context id=" db2tables "targetruntime=" MyBatis3 "> <commentgenera tor> <property name= "Suppressdate" value= "true"/> <property name= "Suppressallcomments" V Alue= "true"/> </commentGenerator> <!--database link Address account password--<jdbcconnection driverclass= "C Om.mysql.jdbc.Driver "connectionurl=" Jdbc:mysql:// "userid=" root "password=" hongda$  123456 "> </jdbcConnection> <javaTypeResolver> <property name=" Forcebigdecimals " Value= "false"/> </javaTypeResolver> <!--generate model class storage location--<javamodelgenerator target Package= "Com.example.scheduleService.model" targetproject= "Src/main/java" > <property name= "Enablesubpacka Ges "value=" true "/> <Property Name= "Trimstrings" value= "true"/> </javaModelGenerator> <!--build Map file storage location-&lt ; Sqlmapgenerator targetpackage= "Com.example.scheduleService.mapper" targetproject= "Src/main/java" > <prope Rty name= "Enablesubpackages" value= "true"/> </sqlMapGenerator> <!--generated DAO class storage location-<! --client-side code that generates easy-to-use code for model objects and XML configuration files type= "Annotatedmapper", generate Java Model and annotation-based mapper object type= "Mixedmapper", generate the annotation-based Java Model and the corresponding Mapper object type= "Xmlmapper", generate Sqlmap XML file and stand-alone mapper interface--<javaclientgenerator type= "Annotatedmapper" targetpackage= "Com.example.scheduleService.dao" Targetprojec t= "Src/main/java" > <property name= "enablesubpackages" value= "true"/> &LT;/JAVACLIENTGENERATOR&G        T <!--generate the corresponding table and class name--<!--<table tablename= "Stocktradeinfo" domainobjectname= "Stocktradeinfo" Enablecountbye Xample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table>--> <table tablename= "theme" Domainobjectname= "theme" Enable Countbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table> <table tablename= "Stocktheme" domainobjectname= "Stocktheme" en Ablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= " False "Selectbyexamplequeryid=" false "></table>   </context></generatorConfiguration> 

3. Create the corresponding Model,mapper,dao folder according to the configuration

4. Use mybatis-generator:generate in Maven to produce related classes based on the table in the database, Mapper


The automatic production of the Mapper

1. No @mapper annotations

2. The primary key ID is taken with the insert

Automatic production using Mybatis-generator in Springboot

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: 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.