The use _java of MyBatis reverse engineering

Source: Internet
Author: User
Tags generator

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 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 generator Configuration" "1.0//en "> <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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.