Preparatory work:
1. Database Drivers
2.generatorConfig Drive, (: https://github.com/mybatis/generator/releases)
3.generatorconfig.xml configuration file, as follows (note: This file cannot be commented on while it is running.) ):
<?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-driven
<classpathentry location= "Webroot/web-inf/lib/mysql-connector-java-5.1.8-bin.jar"/>
<context id= "Db2tables" targetruntime= "MyBatis3" >
<commentGenerator>
<property name= "Suppressdate" value= "true"/>
<property name= "Suppressallcomments" value= "true"/>
</commentGenerator>
<!--database link Address account password--
<jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "Jdbc:mysql://192.168.1.88:3306/test" userId = "Zhengshou" password= "123456" >
</jdbcConnection>
<javaTypeResolver>
<property name= "Forcebigdecimals" value= "false"/>
</javaTypeResolver>
<!--generate model class storage location-
<javamodelgenerator targetpackage= "Com.adon.model" targetproject= "src" >
<property name= "Enablesubpackages" value= "true"/>
<property name= "Trimstrings" value= "true"/>
</javaModelGenerator>
<!--generate Map file storage location--
<sqlmapgenerator targetpackage= "com.adon.mapping" targetproject= "src" >
<property name= "Enablesubpackages" value= "true"/>
</sqlMapGenerator>
<!--generate a DAO class storage location-
<javaclientgenerator type= "Xmlmapper" targetpackage= "Com.adon.dao" targetproject= "src" >
<property name= "Enablesubpackages" value= "true"/>
</javaClientGenerator>
<!--generate the corresponding table and class name, TableName and domainobjectname are required, respectively, represent the database table name and generated strength class name, the rest can be customized to choose (generally false). -
<table tablename= "user" domainobjectname= "user" enablecountbyexample= "false" enableupdatebyexample= "false" Enabledeletebyexample= "false" enableselectbyexample= "false" Selectbyexamplequeryid= "false" ></table>
</context>
</generatorConfiguration>
Open cmd, go to the project root directory, run the code (note the path problem):
Java-jar Webroot/web-inf/lib/mybatis-generator-core-1.3.2.jar-configfile Src/config/generatorconfig.xml- Overwrite
Automatic generation of DAO, Model, mapping related files using Mybatis-generator