Recently learning MyBatis, similar hibernate,mybatis also have reverse engineering can directly generate code (MAPPING,XML,POJO), facilitate rapid development. It's Mybatis-generator-core-1.3.2.jar this package. Here I use the MySQL database.
1. Download Mybatis-generator-core-1.3.2.jar and Mysql-connector-java-5.1.13-bin.jar, you can download it here http://maven.outofmemory.cn/ Org.mybatis.generator/mybatis-generator-core/1.3.2/
2. Create a new folder, move the Mybatis-generator-core-1.3.2.jar and Mysql-connector-java-5.1.13-bin.jar downloaded in step 1th to the folder, and create a new src folder in the root directory of the folder.
3. Create a new 1 txt text document in the folder root directory, write 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. New Generatorconfig.xml and configure the reverse engineering information in the following:
<?xml version= "1.0" encoding= "UTF-8"?> <! DOCTYPE generatorconfiguration Public "-//mybatis.org//dtd mybatis generator Configuration" "1.0//en Mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <classpathentry location= "Mysql-connector-java-5.1.13-bin.jar"/> <context id= "db2tables" targetruntime= "MyBatis3" > < commentgenerator> <property name= "Suppressdate" value= "true"/> <property name= "SuppressAllComments" Value= "true"/> </commentGenerator> <!--metabase connection--> <jdbcconnection driverclass= " Com.mysql.jdbc.Driver "connectionurl=" Jdbc:mysql://localhost:3306/login "userid=" root "password=" root "> </ jdbcconnection> <javaTypeResolver> <property name= "Forcebigdecimals" value= "false"/> </ Javatyperesolver> <!--configuration generated Pojo entity classes--> <javamodelgenerator targetpackage= "Tse.model" src "> <property name=" enablesubpackages "value=" true "/> <property"Trimstrings" value= "true"/> </javaModelGenerator> <!--configuration generated XML--> <sqlmapgenerator targetpackage = "tse.mapping" targetproject= "src" > <property name= "enablesubpackages" value= "true"/> </sqlmapgenerator > <!--configuration generated mapping interface--> <javaclientgenerator type= "Xmlmapper" targetpackage= "tse.mapping" Targetproject = "src" > <property name= "enablesubpackages" value= "true"/> </javaClientGenerator> <!--configuration Reverse engineering table, TableName available wildcard% matches all tables--> <table tablename= "Login" domainobjectname= "Login" enablecountbyexample= "false" Enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= "false" selectbyexamplequeryid= "False" ></table> </context> </generatorConfiguration>
Remember to modify the Jdbcconnection label database connection configuration and the table label TableName attribute, if all the tables in your database want to reverse engineering, you can set the TableName value directly to%, that is, match all tables, But at this point the Domainobjectname attribute will be removed.
Well, with the above steps, the entire directory structure should be this way
The SRC folder is still an empty folder
At this point, run the root of the bat file, in the SRC directory can be seen to generate the code you want to
The above is a small set to introduce the MyBatis reverse engineering of the use of relevant knowledge, mainly to introduce the use of reverse engineering, this time a friend will ask, then how do I let the reverse project to generate their own definition of the code format. Don't worry, the next one I will talk about Mybatis-generator-core-1.3.2.jar package modification and packaging. Interested friends continue to pay attention to this site!