Mybatis-generator configured and used on eclipse

Source: Internet
Author: User

Before using the MyBatis frame, it is the code of the hand knocking, feel good trouble appearance. I'm going to search the internet today. MyBatis Automatic build tool, found on the official website recommended MyBatis Generator This build tool. Website Recommended Address: http://mybatis.github.io/generator/index.html

Then I'll give you a detailed introduction to the MyBatis generator configuration process and how to use it.

    • mybatis-generator Configuration: 1. Installing the Mybatis-generator plugin
1.1 First, you have to have MyBatis generator this plugin. So, offline install Mybatis-generator plugin:: http://download.csdn.net/detail/wild_elegance_k/8999513

1.2 Installing the Mybatis-generator plugin:

Unzip the downloaded file and copy the "features" and "plugins" to the appropriate directory in the Eclipse's installation directory.

2. Restart Eclipse, then right-click on the project to see






after creating a new generatorconfig.xml, we have to configure it, first of all, what are the major configuration items in this XML file, or what configuration items we have to fill out?
    1. Jdbcconnection --- database link URL, user name, password
    2. Javamodelgenerator--- generate the package name and location of the model, which is the storage path configuration of some entity classes used in MyBatis
    3. Sqlmapgenerator --- generated mapping file registration and location , is the corresponding MyBatis write SQL statement XML file storage path configuration
    4. Javaclientgenerator--- generate DAO's package name and location , is the mybatis inside the DAO interface's storage path
    5. Table --- This configuration item is a database table that is configured to operate in a project

For specific configurations, see the Generator.xml in my project below:

<?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-->< Classpathentrylocation= "D:\Applications\ProgrammingTools\maven\MavenRepository\mysql\mysql-connector-java\ 5.1.36\mysql-connector-java-5.1.36.jar "/><context id=" Context1 "> <commentGenerator> <!-- Whether to remove automatically generated comments true: Yes: false: No---<property name= "suppressallcomments" value= "true"/> </commentgenerator&gt ;<!--Database link URL, user name, password--><jdbcconnection driverclass= "Com.mysql.jdbc.Driver" connectionurl= "jdbc:mysql:// Localhost:3306/ssm1 "userid=" root "password=" root "/><!--generate the package name and location of the model--><javamodelgenerator Targetpackage= "com.yc.ssm.cinema.entity" targetproject= "Cinema/src/main/java"/><!--generated mapping file registration and location-->< Sqlmapgenerator targetpackage= "Com.yc.ssm.cinema.mapper" targetproject= "Cinema/src/main/java"/><!--generate DAO's package name and location--><javaclientgenerator targetpackage= " Com.yc.ssm.cinema.dao "targetproject=" Cinema/src/main/java "type=" Xmlmapper "/><!--those tables to be generated (change tablename And Domainobjectname will be OK)--><table schema= "Ssm1" tablename= "Filminfo" domainobjectname= "Filminfo" Enablecountbyexample= "false" enableupdatebyexample= "false" enabledeletebyexample= "false" enableselectbyexample= " False "Selectbyexamplequeryid=" false "><columnoverride column=" Filmid "property=" Filmid "/>< Columnoverride column= "Filmname" property= "Filmname"/><columnoverride column= "TYPEID" property= "TYPEID"/> <columnoverride column= "actor" property= "actor"/><columnoverride column= "director" property= "director"/ ><columnoverride column= "Ticketprice" property= "Ticketprice"/></table><table tableName= " Filmtype "Domainobjectname=" Fipltype "enablecountbyexample=" false "enableupdatebyexample=" false " Enabledeletebyexample= "false" enableSelectbyexample= "false" Selectbyexamplequeryid= "false" ><columnoverride column= "TYPEID" property= "TYPEID"/ ><columnoverride column= "TYPENAME" property= "TYPENAME"/></table></context></ Generatorconfiguration>

It is particularly noteworthy that when we use Eclipse's Mybatis-generator plugin, we create a generatorconfig.xml file in the project, so the targetproject= "" in the XML file This item needs to be configured with the name of the project. But I am in the configuration today, my project name is cinema, and then targetproject the configuration of targetproject= "Cinema", however, this is not a good thing, after the configuration of the button below the point, the program has always been shown to run successfully, However, in the package structure of the project, the document was not seen. So this configuration item needs to be particularly noteworthy, and later a variety of solutions, finally found the correct configuration:

I'll take the javamodelgenerator configuration as an example:

<javamodelgenerator targetpackage= "com.yc.ssm.cinema.entity" targetproject= "Cinema/src/main/java"/>

This configuration is to specify the path of the targetproject below the Src/main/java package under the Cinema project.


    • Mybatis-generator using:

Once configured, it is a one-click operation when used:



This time if you can see that the package specified in the configuration item is no longer empty, it means that the generate is successful.






Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Mybatis-generator configured and used on eclipse

Related Article

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.