`

iBatis辅助工具iBator的使用方法

阅读更多

iBator是一个iBatis相关代码的自动生成工具。
1、安装iBator的插件
在Eclipse中,使用添加站点的方法,输入网址http://ibatis.apache.org/tools/ibator,进行iBator的安装。
2、建议不要直接在使用iBatis的项目里直接使用iBator,推荐另外单独建立一个项目来生成。比如,建立一个项目叫:IbatorPrj
3、右键点击IbatorPrj这个项目,如果刚才的插件安装正确的话,就会看到一个“Add iBATOR to the build path”的选项,点击一下。
4、创建iBator的配置文件。下面是我的例子,大家在实际使用的过程中,需要根据自己的情况进行相应的修改。
主要就是数据库JDBC库的路径、数据库驱动的类名、项目的名称、包名等。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ibatorConfiguration
  PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN"
  "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd">

<ibatorConfiguration>
        <classPathEntry location="c:\javaLibs\MySql\mysql-connector-java-5.0.6-bin.jar" />

        <ibatorContext id="SampleiBator" targetRuntime="Ibatis2Java5">
                <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost/sample" userId="root" password="admin">
                </jdbcConnection>

                <javaTypeResolver>
                        <property name="forceBigDecimals" value="false" />
                </javaTypeResolver>

                <javaModelGenerator targetPackage="com.sample"
                        targetProject="IbatorPrj\src">
                        <property name="enableSubPackages" value="true" />
                        <property name="trimStrings" value="true" />
                </javaModelGenerator>

                <sqlMapGenerator targetPackage="com.sample.xml"
                        targetProject="IbatorPrj\src">
                        <property name="enableSubPackages" value="true" />
                </sqlMapGenerator>

                <daoGenerator type="GENERIC-CI" targetPackage="com.sample.dao"
                        targetProject="IbatorPrj\src">
                        <property name="enableSubPackages" value="true" />
                </daoGenerator>

                <table schema="sample" tableName="tab1" domainObjectName="JavaBean1">
                        <property name="useActualColumnNames" value="false" />
                        <generatedKey column="ID" sqlStatement="MySql" identity="true" />
                </table>

        </ibatorContext>
</ibatorConfiguration>
5、配置文件生成完毕后,右键点击这个文件,选择“Generate iBatis Artifact”,然后你就在配置的文件夹下找到自动生成的文件了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics