directly into the topic, as the project was chosen using MAVEN to build, so chose to take advantage of the way Maven was built. (There is also a self-Baidu)
First, add the plugin in Pom.xml
<plugin> <groupId>Org.mybatis.generator</groupId> <Artifactid>Mybatis-generator-maven-plugin</Artifactid> <version>1.3.2</version> <Configuration> <!--location of the configuration file - <ConfigurationFile>Src/main/resources/personal-generatorconfig.xml</ConfigurationFile> <verbose>True</verbose> <Overwrite>True</Overwrite> </Configuration> </plugin>
II. Configuration XML file
The XML file mainly uses the existing database tables, through the configuration, to make the database table information and Pojo, Mapper.xml, DAO produce contact
<?XML version= "1.0" encoding= "UTF-8"?> <!DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis Generator Configuration 1.0//en" "Http://myb Atis.apache.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorconfiguration>
<!-- database configuration information, using the project's jdbc.properties to introduce this XML-- <PropertiesResource= "Jdbc.properties"></Properties> <!--Database driver package, using absolute path here I am using MySQL driver that is consistent with my project dependent version - <Classpathentry Location= "D:\maven\localRpertory\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar" /> <!--Environment Configuration **************************************************
Id= "Custom Configuration Name" Targetruntime= "MyBatis version" - <ContextID= "Ssm-context"Targetruntime= "MyBatis3"> <Commentgenerator> <!--Remove Auto-generated annotations - < Propertyname= "Suppressallcomments"value= "true" /> </Commentgenerator> <!--Database Connection Configuration - <!--Database ===============================================
driverclass= "Drive" connectionurl= "Database url" userid= "user" password= "password"
====================================================== - <jdbcconnectionDriverclass= "${driver}"Connectionurl= "${url}"userId= "${username}"Password= "${password}" /> <!--jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://localhost:3306/test" userId = "root" password= "MySQL"/ - <!--Java Data type separator, data type conversion ===================== Property attribute Name= "forced double precision" value= "not" non-mandatory option ============ ==================================== - <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false" /> </Javatyperesolver> <!--Java Model Builder ======================================= targetpackage= "target path for makefile" targetproject= " Existing Project Package "enablesubpackages-can omit the corresponding constraint name, true-Yes, can omit tb_generator trimstring-validation string, true-Yes ================================ - <JavamodelgeneratorTargetpackage= "Com.my.traffic.domain"Targetproject= "Src/main/java" /> <!--SQL Map File Generator ======================================= targetpackage= "target path to makefile" targetproject= "Existing Project Package" enablesubpackages-can omit the corresponding constraint name, true-Yes, you can omit tb_generator = = ========================================== - <SqlmapgeneratorTargetpackage= "Com.my.traffic.mapping"Targetproject= "Src/main/java" /> <!--Java Delegate Object DAO generator, interface ============================= here in order to be more flexible, I did not choose to generate a DAO interface, if needed to generate can put the following configuration uncomment type= "" Targetpackage= "The target path of the makefile" targetproject= "Existing Project package" enablesubpackages-can omit the corresponding constraint name, true-Yes, can To omit Tb_generator - <!--<javaclientgenerator type= "Xmlmapper" targetpackage= "Cn.xt.dao" targetproject= "Mybatisgenerate" > <property name= "enablesubpackages" value= "false"/> </ Javaclientgenerator> - <!--database table, existing, generate additional files based on this table ======================= tablename= "Existing form name" Domainobjetctname= "corresponds to the generated file name Prefix "(that is, my table is named Pass_vehivle_info, so I am configuring my generated Pojo named Passvehicleinfo, and the resulting XML is Passvehicleinfomapper.xml) ================== ========================== - <!--Call Log Table - <TableTableName= "Pass_vehicle_info"Domainobjectname= "Passvehicleinfo"> <!--useactualcolumnnames-whether the real column name is used, if false, is controlled by the Columnoverride node, followed by the way the hump is named - < Propertyname= "Useactualcolumnnames"value= "Flase"/> <!--identity column column= "column name" sqlstatement= "some database language" identity= "as the primary key" - <Generatedkeycolumn= "pass_id"SQLStatement= "MYSQL"Identity= "true" /> </Table> </Context></generatorconfiguration>
Third, run generator plug-in
Operating method: In Eclipse, select the Pom.xml file, right-click the run As-->maven build...--> enter in the Goals box: Mybatis-generator:generate Run
In this way, the relevant files will be generated under the configured path, if necessary, can be self-deletion, renaming, very convenient
Reverse generation of DAO, Mapper.xml, Pojo (via maven) using the MyBatis generator plugin