MyBatis Reverse Engineering (upper)

Source: Internet
Author: User

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)

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: info-contact@alibabacloud.com 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.