1. Configure Maven Pom.xml files
Add the following plugins to the Pom.xml:
1 <Build>2 </Plugins>3 ...4 <plugin>5 <groupId>Org.mybatis.generator</groupId>6 <Artifactid>Mybatis-generator-maven-plugin</Artifactid>7 <version>1.3.2</version>8 <Configuration>9 <verbose>True</verbose>Ten <Overwrite>True</Overwrite> One </Configuration> A </plugin> - ... - </Plugins> the </Build>
Configure the MAVEN plug-in, the following need to configure the plug-in needs mybatis-generator configuration file
2. Configuring the Mybatis-generator configuration file
To add a configuration file under resource:
Content of Generatorconfig.xml:
1 <?XML version= "1.0" encoding= "UTF-8"?>2 <!DOCTYPE generatorconfiguration3 Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en"4 "Http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">5 6 <generatorconfiguration>7 <!--OJDBC's jar package -8 <Classpathentry9 Location= "E:/maven/mvn_repository/com/oracle/ojdbc14/14/ojdbc14-14.jar" />Ten <ContextID= "my"Targetruntime= "MyBatis3"> One <Commentgenerator> A < Propertyname= "Suppressdate"value= "false" /> - < Propertyname= "Suppressallcomments"value= "true" /> - </Commentgenerator> the <!--Database connection Information - - <jdbcconnectionDriverclass= "Oracle.jdbc.driver.OracleDriver" - Connectionurl= "JDBC:ORACLE:THIN:@192.168.1.112:1521:ORCL"userId= "KY" - Password= "KY" /> + <!--Model Generation Path - - <JavamodelgeneratorTargetpackage= "Com.dg.bean" + Targetproject= "E:/myworkspace/ssmdemo/src/main/java"> A < Propertyname= "Enablesubpackages"value= "true" /> at < Propertyname= "Trimstrings"value= "true" /> - </Javamodelgenerator> - <!--map XML file generation path - - <SqlmapgeneratorTargetpackage= "Com.dg.mapping" - Targetproject= "E:/myworkspace/ssmdemo/src/main/java"> - < Propertyname= "Enablesubpackages"value= "true" /> in </Sqlmapgenerator> - <!--the Dao build path associated with the XML file (the generated file name is ***mapper.java by default and is used to rename it to ***dao.java) - to <JavaclientgeneratorTargetpackage= "Com.dg.dao" + Targetproject= "E:/myworkspace/ssmdemo/src/main/java"type= "Xmlmapper"> - < Propertyname= "Enablesubpackages"value= "true" /> the </Javaclientgenerator> * $ <!--The target table, if there are multiple tables, configure the copy separately -Panax Notoginseng <TableTableName= "Order_info"Domainobjectname= "Orderinfobean" - Enablecountbyexample= "false"Enableupdatebyexample= "false" the Enabledeletebyexample= "false"Enableselectbyexample= "false" + Selectbyexamplequeryid= "false"> A </Table> the </Context> + </generatorconfiguration>
3. Generate Code
In Eclipse, select the Pom.xml file, right-click the run As-->maven build...--> enter in the Goals box: Mybatis-generator:generate,
MAVEN downloads the plug-in first and then generates the code.
Look at the effect:
Use Maven plugin +mabatis-generator to generate MyBatis files under Eclipse