There are a lot of things on the web about the database table mapping configuration that Mabatis-generator automatically generates Mabatis and the usage of beans and DAO, broadly divided into these types: Eclipse plug-in generation, jar package generation, MAVEN plugin + Mabatis-generator generated, this is only the last usage. 1. Configure Maven Pom.xml files
Add the following plugins to the Pom.xml:
<build>
</plugins> ...
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId> mybatis-generator-maven-plugin</artifactid>
<version>1.3.2</version>
< configuration>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
</plugin> ...
</plugins>
</build>
Configure the MAVEN plug-in, below need to configure the plug-in needs mybatis-generator configuration file 2. Configure Mybatis-generator Profile
Add the configuration file to resource:
Generatorconfig.xml content:
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Htt
P://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <!--ojdbc Jar-- <classpathentry location= "E:/maven/mvn_repository/com/oracle/ojdbc14/14/ojdbc14-14.jar"/> <contex T id= "my" targetruntime= "MyBatis3" > <commentGenerator> <property name= "Suppressdate" value
= "false"/> <property name= "suppressallcomments" value= "true"/> </commentGenerator> <!--database connection information--<jdbcconnection driverclass= "Oracle.jdbc.driver.OracleDriver" connecti Onurl= "JDBC:ORACLE:THIN:@192.168.1.112:1521:ORCL" userid= "KY" password= "KY"/> <!--model Generation Road Size--<javamodelgenerator targetpackage= "Com.dg.bean" targetproject= "E:/myworkspace/ssmdemo/src/main/java "> <property name=" enablesubpackages "value=" true "/> &
Lt;property name= "Trimstrings" value= "true"/> </javaModelGenerator> <!--map XML file generation path-- <sqlmapgenerator targetpackage= "com.dg.mapping" targetproject= "E:/myworkspace/ssmdemo/src/main/java" > <property name= "enablesubpackages" value= "true"/> </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)-<javaclientgenerator targetpackage= "COM.DG . Dao "targetproject=" E:/myworkspace/ssmdemo/src/main/java "type=" Xmlmapper "> <property name=
"Enablesubpackages" value= "true"/> </javaClientGenerator> <!--target table, if you have more than one table, configure the copy individually- <table tablename= "Order_info" domainobjectname= "Orderinfobean" enablecountbyexample= "false" enableUp
Datebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" > </table> </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 will download the plugin first, Then generate the code.
Look at the effect:
Then, according to our habits will be generated by the name of the file (note the XML file namespace do not forget to change).