Steps:
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> <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≪/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.org//dtd mybatis Generator Configuration 1.0//en" "Http://mybatis.org/dtd/mybatis-generator-config_1_0. 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://127.0.0.1:3306/longhubang "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-< ; 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"/> </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
Attention:
The automatic production of the Mapper
1. No @mapper annotations
2. The primary key ID is taken with the insert
http://blog.csdn.net/yezhuanxu/article/details/53483130
Automatic production using Mybatis-generator in Springboot