Install, configure, and use the ibator plugin

Source: Internet
Author: User

1. ibator Introduction

Ibator is the code generator of ibatis. Its original name is abator. Later its name was changed to ibator, and the code structure was modified accordingly. Therefore, the configurations of the two are different. Ibator can generate the DaO layer and do layer of a table (or multiple tables) in a database and the configuration complying with ibatis specifications, it reduces the workload of writing configuration files, creating do and Dao, and creating simple CRUD (creation, retrieval, update, and deletion). On this basis, we can modify it, rather than simply implementing it again, this greatly reduces our workload. This advantage is even more obvious when many tables are operated.

2. Install the ibator plugin

The ibator plug-in can be installed in multiple ways, and both eclipse and myeclipse are supported.

This document introduces the local Installation Method in Eclipse:

First, download the plug-in:

Follow these steps:

Open the plug-in installation interface in the eclipse menu: Help-> installnew software...

Next, click Next and restart eclipse.

Verify whether the plugin is successfully installed:

Choose File> New> other from the eclipse menu bar and enter "IB" in the search box. If yes, the installation is successful.

3. ibator Configuration

 Create a new Java project in eclipse, right-click New> Other and select abator for ibatisconfiguration file. The default filename is ibatorconfig. xml. Click "finish". eclipse will create the ibatorconfig. xml file under the program root directory and open and edit it. The initial content is as follows:

<?XMLVersion = "1.0" encoding = "UTF-8"?>

<! Doctype ibatorconfiguration public "-//ApacheSoftwarefoundation // DTDApacheIbatisIbatorConfiguration 1.0 // en "" http://ibatis.apache.org/dtd/ibator-config_1_0.dtd ">

<Ibatorconfiguration>

<Ibatorcontext id = "context1">

<Jdbcconnection driverclass = "??? "Connectionurl = "??? "Userid = "??? "Password = "??? "/>

<Javamodelgenerator targetpackage = "??? "Targetproject = "??? "/>

<Sqlmapgenerator targetpackage = "??? "Targetproject = "??? "/>

<Daogenerator targetpackage = "??? "Targetproject = "??? "Type =" GENERIC-CI "/>

<Table schema = "??? "Tablename = "??? ">

<Columnoverride column = "??? "Property = "??? "/>

</Table>

</Ibatorcontext>

</Ibatorconfiguration>

Configure as needed:

<?XMLVersion = "1.0" encoding = "UTF-8"?>

<! Doctype ibatorconfiguration public "-//ApacheSoftwarefoundation // DTDApacheIbatisIbatorConfiguration 1.0 // en "" http://ibatis.apache.org/dtd/ibator-config_1_0.dtd ">

<Ibatorconfiguration>

<! -- Note that the classpathentry location is not in the default configuration file. You must manually add the attribute to specify the database driver path. -->

<Classpathentry location = "E :/MySQL-Connector-java-5.1.30.jar "/>

<Ibatorcontext id = "context1">

<! -- Driver name, Database URL, user name, password -->

<Jdbcconnection driverclass = "com. MySQL. JDBC. Driver" connectionurl = "JDBC: mysql ://Localhost: 3306/test "userid =" root "Password =" 123 "type =" codeph "text =" codeph "/>

<! -- Targetan generator targetpackage: package name, targetproject: Project name -->

<Javamodelgenerator targetpackage = "com. Domain" targetproject = "ibatisdemo"/>

<! -- Ing file generator -->

<Sqlmapgenerator targetpackage = "com. config" targetproject = "ibatisdemo"/>

<! --DaoGenerator, type generationDaoFile type, you can choose ibatis, spring, generic-ci, GENERIC-SI -->

<Daogenerator targetpackage = "com. Dao" targetproject = "ibatisdemo" type = "Spring"/>

<! -- Tablename is the table name mapped to the table name and domainobjectname is the corresponding class name. If this parameter is left blank, the table name is the same by default. -->

<Table schema = "" tablename = "user" domainobjectname = "usertbldomain">

<! -- Columnoverride: Specifies the attribute name. If this parameter is not specified, it is processed according to the default rule: letters are first written into smaller letters, followed by underscores (_), followed by uppercase letters (_). -->

<Columnoverride column = "ID" property ="UID"/>

</Table>

<Table schema = "" tablename = "role" domainobjectname = ""/>

<Table schema = "" tablename = "location"/>

</Ibatorcontext>

</Ibatorconfiguration>

4. ibator code generation and Optimization

After the configuration is complete, right-click the configuration file and select generateibatis artifacts

After the execution is complete, you will find that the specified directory and file have been generated under the SRC project:

When you open the file, you find that the ibator generates comments for each method and Configuration During generation, which sometimes seems awkward and useless and affects your mood. Is there a way to prevent it from generating comments? Yes, but we can only modify the source code of the source code ibator. After the plug-in is installed, the source file under the installation directory is eclipse \ plugins \ Org. apache. ibatis. ibator. core_1.2.1 \ ibator-src.zip, decompress and copy to eclipse

Optimization 1: clear comments

Find the file Org. apache. ibatis. abator. internal. defaultcommentgenerator. java: clear all the content of methods that do not need to generate comments. These are void methods and there will be no other applications.

Optimization 2: Clear unnecessary methods in Dao

In addition, there are a lot of example methods in the generated Dao and Dao implementations, as well as in the configuration file. If you cannot use these methods, you can also find the following two classes:

Getcompilationunits method in org. Apache. ibatis. ibator. generator. ibatis2.dao. daogenerator

Getsqlmapelement method in org. Apache. ibatis. ibator. generator. ibatis2.sqlmap. sqlmapgenerator

Comment out all the calls to the example method.

Optimization 3: remove the ID prefix ibatorgenerated _

In addition, the ID in the generated configuration file also has the prefix "ibatorgenerated _", which also seems too long. In this case, find the file:

Org. Apache. ibatis. ibator. config. mergeconstants, set the value of new_xml_element_prefix to null.

You can also download and replace the optimized JAR file.

Install, configure, and use the ibator 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.