About using mybatis Generator to automatically generate code, mybatisgenerator

Source: Internet
Author: User

About using mybatis Generator to automatically generate code, mybatisgenerator

1. Install the mybatis plug-in:

In eclipse, click help --> Install New Software... --> Add --> local to select the eclipse directory in the plug-in ---> updatesizefile (for details about the plug-in package, see mybatis-generator-master.rar)

Http://download.csdn.net/detail/u010489036/8593745

 

2. Create generatorConfig. xml:

Right-click the project --> New ---> Other --> mybatis plug-in, and click Next to generate the generatorConfig. xml file.

 

3. Configure the generatorConfig. xml file (the simplest way to create a DB2 database is used here)

<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE generatorConfiguration PUBLIC "-// mybatis.org//DTD MyBatis Generator Configuration 1.0 //" http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd "> <generatorConfiguration> <context id =" context1 "> <jdbcConnection driverClass =" com. ibm. db2.jcc. DB2Driver "connectionURL =" jdbc: db2: // ip: port/Database Name "userId =" userid "password =" password "/> <javaModelGenerator targetPackage =" com. dao. ibatis. model "t ArgetProject = "project name/src/dao"/> <sqlMapGenerator targetPackage = "com. dao. ibatis. mapper "targetProject =" project name/src/dao "/> <javaClientGenerator targetPackage =" com. dao. ibatis. client "targetProject =" project name/src/dao "type =" XMLMAPPER "/> <! -- Table Name List multiple tables can be written here --> <table schema = "" tableName = "database indicates" domainObjectName = "PO Object Name"/> </context> </generatorConfiguration>Xml configuration file

 

4. Add the corresponding db2 driver jar package (db2jcc. jar), which needs to be added based on the actual database. Http://download.csdn.net/detail/u010489036/8593783

 

5. Right-click the mybatis file and execute:

 

 

At this point, if the database connection is normal, the corresponding PO object will be created.

--- ===================================================== ======= --

I have encountered an exception in the project. Here, I would like to share with you:

 

I found a lot of information on the Internet and did not provide a clear description of this exception. At first I thought it was a configuration file problem. I tried to change the eclipse version, JDK version, and other methods, is determined because

The version of the db2 driver jar package downloaded from the internet is incorrect ).

 

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.