Recently learning MyBatis, similar to Hibernate,mybatis also have reverse engineering can directly generate code (MAPPING,XML,POJO), convenient for rapid development. It's Mybatis-generator-core-1.3.2.jar this rack of bags. I'm using the MySQL database here.
1. Download Mybatis-generator-core-1.3.2.jar and Mysql-connector-java-5.1.13-bin.jar, you can download here http://maven.outofmemory.cn/ Org.mybatis.generator/mybatis-generator-core/1.3.2/
2. Create a new folder, move the 1th step download Mybatis-generator-core-1.3.2.jar and Mysql-connector-java-5.1.13-bin.jar to the folder, and create a new src folder at the root of the folder.
3. Create a new 1 txt text document in the folder root and write the code:
Java-jar Mybatis-generator-core-1.3.2.jar-configfile Generatorconfig.xml-overwrite
Then change the file name suffix of the txt text document to bat.
4. Create a new generatorconfig.xml and configure the reverse engineering information as follows:
<?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> <Classpathentry Location= "Mysql-connector-java-5.1.13-bin.jar"/> <ContextID= "Db2tables"Targetruntime= "MyBatis3"> <Commentgenerator> < Propertyname= "Suppressdate"value= "true"/> < Propertyname= "Suppressallcomments"value= "true"/> </Commentgenerator> <!--Configure database Connections - <jdbcconnectionDriverclass= "Com.mysql.jdbc.Driver"Connectionurl= "Jdbc:mysql://localhost:3306/login"userId= "root"Password= "root"> </jdbcconnection> <Javatyperesolver> < Propertyname= "Forcebigdecimals"value= "false"/> </Javatyperesolver> <!--Configuring the generated Pojo entity class - <JavamodelgeneratorTargetpackage= "Tse.model"Targetproject= "src"> < Propertyname= "Enablesubpackages"value= "true"/> < Propertyname= "Trimstrings"value= "true"/> </Javamodelgenerator> <!--Configuring the generated XML - <SqlmapgeneratorTargetpackage= "Tse.mapping"Targetproject= "src"> < Propertyname= "Enablesubpackages"value= "true"/> </Sqlmapgenerator> <!--Configuring the generated mapping interface - <Javaclientgeneratortype= "Xmlmapper"Targetpackage= "Tse.mapping"Targetproject= "src"> < Propertyname= "Enablesubpackages"value= "true"/> </Javaclientgenerator><!--Configure the Reverse engineering table, TableName available wildcard% match all tables - <TableTableName= "Login"Domainobjectname= "Login"Enablecountbyexample= "false"Enableupdatebyexample= "false"Enabledeletebyexample= "false"Enableselectbyexample= "false"Selectbyexamplequeryid= "false"></Table> </Context></generatorconfiguration>
Remember to modify the configuration of the database connection of the jdbcconnection tag and the tableName property of the table tag, if all the tables in your database want to reverse the project, you can set directly The TableName value is%, which matches all tables, but at this point the domainobjectname attribute is removed.
Well, through the above steps, the entire directory structure should be like this
The SRC folder is also an empty folder
At this point, run the bat file in the root directory, and you will see the code generated in the SRC directory.
This article is mainly about the use of reverse engineering, this time a friend will ask, then how can I get the reverse engineering to generate their own definition of code format it. No hurry, Next I'll talk about the modification and packaging of the Mybatis-generator-core-1.3.2.jar rack package.
MyBatis Reverse Engineering (upper)