Generate MyBatis code with MAVEN plugin

Source: Internet
Author: User

Now code management is basically using MAVEN management, MAVEN benefits here is not much to say, we use Baidu Search will have a lot of introduction, this article describes how to use MAVEN tools to generate MyBatis code and mapped files.

I. Configuring MAVEN pom.xml Files

Add the following plugins to the Pom.xml:

<Plugin><GroupId>org.mybatis.generator</GroupId><Artifactid>mybatis-generator-maven-plugin</Artifactid><Version>1.3.2</Version><Configuration> < verbose>true</verbose> < overwrite>true</overwrite > </ configuration> </plugin>       

Configure the MAVEN plug-in, you need to configure the plug-in configuration file

Second, plug-in configuration file

MAVEN's project configuration file storage path such as:

The plugin will read the Generatorconfig.xml file in the Src/main/resources directory by default.

The specific configuration is 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="D:\repo\mysql\mysql-connector-java\5.1.6\mysql-connector-java-5.1.6.jar" /><Context Id="Context1" Targetruntime="MyBatis3"><Jdbcconnection Driverclass="Com.mysql.jdbc.Driver" Connectionurl="Jdbc:mysql://xxxxxxx:8406/cl_demo?useunicode=true&amp;characterencoding=utf-8" Userid="Root" Password="Password" /><Javamodelgenerator Targetpackage="Xxx.account.model" Targetproject="D:\workspace\ Project name \src\main\java" /><Sqlmapgenerator Targetpackage="Xxxx.account.persistence" Targetproject="D:\workspace\ project name \ Package Name \src\main\resources" /><Javaclientgenerator Targetpackage="Xxxx.account.persistence Targetproject="D:\\workspace\ Project Name \src\main\java " Type="Xmlmapper" /><Table Schema="Cl_demo" TableName="Tb_user" /><Table Schema="Cl_demo" TableName="Tb_role" /><Table Schema="Cl_demo" TableName="Tb_permission" /><Table Schema="Cl_demo" TableName="Tb_role_user" /> <table  schema = "Cl_demo"  tablename=  "tb_permission_role"  /> </context ></ generatorconfiguration>         

In this example, the MySQL database is used and the JDBC driver for the MySQL database needs to be specified.

1, specify the URL of the connection database;

2. Specify the package name that generates the data model object, such as Com.xxx.xxx.model, Targetproject specifies the project and the directory where the model is stored.

3,Sqlmapgenerator need to set the package name, and the path to store the mapping file. If you manage with Maven, the generic XML file is placed in the Src/main/resources directory.

4,Javaclientgenerator need to set the package name and path.

6. Next, you need to configure the name of the table you need to generate.

Third, generate code

After the configuration is done, you can now generate the code,

If it is in Eclipse, select the Pom.xml file, right-click the run As-->maven build...--> enter in the Goals box:mybatis-generator:generate

If you enter the MAVEN command at the command line, note: This command must be running under the current project directory:

MVN mybatis-generator:generate

After the code is generated, the merit is farewell.

Reprint: http://my.oschina.net/lilw/blog/168304

Generate MyBatis code with MAVEN plugin

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.