1. Add the Mybatis-generator plugin to the Pom.xml file
Under the project node, add the following code:
<build> <finalName></finalName> <plugins> <plugin> <groupid>org.apa Che.maven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactId> <v
Ersion>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration
> </plugin> <!--mvn Mybatis-generator:generate--<plugin> <groupId>org.mybatis.generator</groupId> <artifactid>mybatis-generator-maven-plugin</artif actid> <version>1.3.2</version> <configuration> <VERBOSE>TRUE&L T;/verbose> <overwrite>true</overwrite> <configurationfile>src/main/resources /generatorconfig.xml</Configurationfile> </configuration> <dependencies> <!--database driver <dependency> <groupId>com.oracle</groupId> <ARTIFACTID>OJDBC14</ARTIFAC tid> <version>${oracle.version}</version> <scope>runtime</scope> </depend ency> </dependencies> </plugin> </plugins> <resources> <RESOURCE&G
T <directory>src/main/java</directory> <includes> <include>**/*.xml</include> &L t;include>**/*.sql</include> </includes> <filtering>false</filtering> </resource&
Gt <resource> <directory>src/main/resources</directory> </resource> </resources> < /build>
2.maven The default resource file is under: src/main/resources, add generatorconfig.xml file under Resources
Generatorconfig.xml content is as follows:
<?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> <!--Database Driver package Location-- <!--because the database driver package is already configured when you add a plug-in to Pom.xml, you do not have to configure it here-<!--<classpathentry location= "D:\generator\ Mysql-connector-java-5.1.34.jar "/>-<!--<classpathentry location=" E:\Database\Oracle\jdbc\lib\ojdb
C14.jar "/>--> <context id=" db2tables "targetruntime=" MyBatis3 "> <commentGenerator> <property name= "Suppressallcomments" value= "true"/> </commentGenerator> <!--number According to the library link URL, username, password--<!--<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql:/ /localhost:3306/my_db?characterencoding=utf8 "userid=" root "password=" 123456 ">" <jdbcconnection dri Verclass= "Oracle.jdbc.driver.OracleDriver" connectionurl= "Jdbc:oracle:thin: @localhost: Orcl" userid= "Scott" password = "Tiger" > </jdbcConnection> <javaTypeResolver> <property name= "Forcebig Decimals "value=" false "/> </javaTypeResolver> <!--generate the package name and location of the model--and <javamo Delgenerator targetpackage= "Com.test.model" targetproject= "Src/main/java" > <property name= "Enablesubpa Ckages "value=" true "/> <property name=" trimstrings "value=" true "/> </javamodelgenera Tor> <!--generated map file package name and location--<sqlmapgenerator targetpackage= "com.test.mapping" Targetproject = "Src/main/java" > <property name= "enablesubpackages" value= "true"/> </sqlmapgenerator > <!--Generate DAO's package name and location--<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.test.dao" targetproject= "Src/main/java" >
<property name= "Enablesubpackages" value= "true"/> </javaClientGenerator> & lt;! --To generate those tables (change TableName and Domainobjectname can)-<table tablename= "admin_division" Domainobjectname= "Admindi Vision "enablecountbyexample=" false "enableupdatebyexample=" false "enabledeletebyexample=" false " Enableselectbyexample= "false" selectbyexamplequeryid= "false"/> <!--<table tablename= "Course_info" Dom Ainobjectname= "Courseinfo" enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= " False "enableselectbyexample=" false "selectbyexamplequeryid=" false "/> <table tablename=" Course_user_info " Domainobjectname= "Courseuserinfo" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "false"/>--</contex T> </generatorConfiguration>
3. Running the Mybatis-generator plugin
On the left side of the interface, right-click Maven build--"New", come out the following interface:
After execution, the console comes out with the following log, which proves the success of the operation:
Then you can go to the corresponding path to see the generated file: