1. Required JAR Package
Mybatis-generator-core-1.3.2.jar Mybatis-generator-core-1.3.2.jar can go http://mvnrepository.com/to search and download the corresponding version of the jar package.
2. Configuring the Generator.xml File
<?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 - <Classpathentry Location= "E:\lichenli\mybatis\generator\mysql-connector-java-5.1.34.jar" /> <ContextID= "Db2tables"Targetruntime= "MyBatis3"> <Commentgenerator> < Propertyname= "Suppressallcomments"value= "true" /> </Commentgenerator> <!--database link URL, user name, password - <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://localhost:3306/en_oa"userId= "Test"Password= "Test"> </jdbcconnection> <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false" /> </Javatyperesolver> <!--Build the package name and location of the model - <JavamodelgeneratorTargetpackage= "Com.demo.oa.model"Targetproject= "E:\lichenli\mybatis\generator\oa\src"> < Propertyname= "Enablesubpackages"value= "true" /> < Propertyname= "Trimstrings"value= "true" /> </Javamodelgenerator> <!--generated map file package name and location - <SqlmapgeneratorTargetpackage= "Com.demo.oa.dao.mapping"Targetproject= "E:\lichenli\mybatis\generator\oa\src"> < Propertyname= "Enablesubpackages"value= "true" /> </Sqlmapgenerator> <!--generate DAO's package name and location - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Com.demo.oa.dao"Targetproject= "E:\lichenli\mybatis\generator\oa\src"> < Propertyname= "Enablesubpackages"value= "true" /> </Javaclientgenerator> <!--to generate those tables (change tablename and Domainobjectname) - <TableTableName= "En_user"Domainobjectname= "Enuser"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> <TableTableName= "EN_DEP"Domainobjectname= "Endepartment"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> <TableTableName= "En_grade"Domainobjectname= "Engrade"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false" /> </Context></generatorconfiguration>
3. Allow commands to generate code
Place the jar package with the configuration file in the same directory, hold down SHIFT right click here to open the Command window, enter the command
Java-jar mybatis-generator-core-1.3. 2. Jar-configfile generator.xml-overwrite
Enter OK.
Automatic generation of DAO, Model, mapping code using Mybatis-generator