Mybatis-generator configured and used on eclipse

Source: Internet
Author: User
Tags generator


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. Install Mybatis-generator plug-in 

1.1 first, you have to have MyBatis generator this plugin. So, offline install Mybatis-generator plugin: Download address: 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. Use of Mybatis-generator:

restart Eclipse, then right-click in the project to see the figure:






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? Jdbcconnection---Database link url, user name, password
Javamodelgenerator---Generate the package name and location of the model, which is the storage path configuration of some entity classes used in MyBatis
Sqlmapgenerator---Generated mapping file registration and location, is the corresponding MyBatis write SQL statement XML file storage path configuration
Javaclientgenerator---Generate DAO's package name and location, is the mybatis inside the DAO interface's storage path
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 -->
<classPathEntry
Location="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>
<!-- Database link URL, username, 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 package name and location -->
<javaClientGenerator targetPackage="com.yc.ssm.cinema.dao" targetProject="Cinema/src/main/java" type="XMLMAPPER" />
<!-- Those tables to be generated (change the tableName and domainObjectName) -->
<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.

















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.