Install and use the MyBatis_Generator plugin.

Source: Internet
Author: User

Install and use the MyBatis_Generator plugin.

MyBatis_Generator_1.3.1.zip

1. Download the installation package

Installation Package name: MyBatis_Generator_1.3.1.zip

 

 

2. install on Eclipse

LAdd plug-insIn the compressed packageFeaturesAnd plugins are copied to the features and plugins folders of eclipse.

 

 

LRestartEclipseTo verify whether the installation is successful.

 

 

The installation is successful!

3 User Guide

After creating a Maven project, follow these steps:

 

 

1.CreateGeneratorConfigFile

 

 

 

 

2. generatorConfig. xmlFile Configuration

JdbcConnection --- Database link URL, user name, and 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--- The registration and location of the generated ing file are the storage path configuration of the xml file corresponding to the SQL statement written by mybatis.

JavaClientGenerator--- Generate the package name and location of DAO, which is the storage path of dao interface in mybatis

Table--- This configuration item is the database table configured for operation in the project.

 

 

 

 

 

(1) Pom. xmlAdd dependency

 

 

 

 

 

 

 

(2) Run the project and run-Maven install

After successful execution, the dependent packages will be downloaded from the repository. (If so, keep skip and build success)

 

(3) Find mysqlJarPackage location

The location of the jar package will be used in the configuration file generatorConfig. xml.

E: \ RepMaven \ mysql-connector-java \ 5.1.38 \ mysql-connector-java-5.1.38.jar

<ClassPathEntry location ="E: \ RepMaven \ mysql-connector-java \ 5.1.38 \ mysql-connector-java-5.1.38.jar"/>

 

 

 

 

(4) View the database information of the table.

<JdbcConnection

DriverClass ="Com. mysql. jdbc. Driver"

ConnectionURL ="Jdbc: mysql: // localhost: 3306/test"UserId ="Root"

Password ="Root"/>

 

<Table tableName ="Users"DomainObjectName ="UserInfo"/>

TableName: database table used to automatically generate code

DomainObjectName: name of the an class corresponding to the database table

 

 

(5) After configuration, run mybatisConfig. xml.

Right-click mybatisConfig. xml and choose generate mybatis ....

 

 

 

(7) View the results and automatically create the code structure:

 

 

 

(8) View detailed code

 

 

 

 

 

 

 

 

 

4. Notes

L generatorConfig. xml must be correctly configured. If an error occurs in the created table name, the following error may occur:

Incorrect Configuration:

 

 

Correct Configuration:

 

 

L The targetProject PATH uses relative paths. Do not use absolute paths. Otherwise, an error is returned:

Incorrect Configuration:

 

 

Error message:

 

 

Correct Configuration:

 

 

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.