【Maek My Eclipse】之iBatis Plugin

时间:2023-01-14 14:42:31

一.安装插件
http://ibatis.apache.org/abator.html下载Eclipse Plugin。插件一共有2种安装方式.
1.远程安装.
 eclipse->Help>Software Updates>Find and Install->Search for new features to install->
 New Remote Site(name:Abator for Eclipse Update Site ,URL:http://ibatis.apache.org/tools/abator)
 ->OK->Abator for Eclipse Update Site->OK
2.手动安装.
 http://ibatis.apache.org/abator.html下载AbatorForEclipse1.1.0.zip,下载后在eclipse中进行操作
 eclipse->Help>Software Updates>Find and Install->Search for new features to install(press "Next" )->
 New Local Site->选种刚才下载的文件->OK
二.建立一个项目
 新建一个Eclipse项目,输入名字,然后选择文件>新建>ABator for iBatis configuration File,选择Location,并且键入File Name:abatorCsonfig.xml。

点击“完成”,Eclipse会在程序根目录下建立abatorCsonfig.xml文件,打开编辑它,内容如下:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE abatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Abator for iBATIS Configuration 1.0//EN" "http://ibatis.apache.org/dtd/abator-config_1_0.dtd" >
<abatorConfiguration >
  <abatorContext >
    <jdbcConnection driverClass="驱动" connectionURL="数据库URL" userId="用户名" password="密码" >
      <classPathEntry location="数据库驱动jar包" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="model层包路径" targetProject="src路径" />
    <sqlMapGenerator targetPackage="map层包路径" targetProject="src路径" />
    <daoGenerator targetPackage="dao层包路径" targetProject="src路径" type="IBATIS" />
    <table schema="表名" tableName="表名" catalog="数据库名">一定要写上,不然会报错的。
    </table>
  </abatorContext>
</abatorConfiguration>

在abatorCsonfig.xml上点击鼠标右键,选择Generate iBATIS Artifact,在src目录下会生成model、map、dao三个目录,文件也建立好了。
 javaModelGenerator:我们常说的ValueObject
 sqlMapGenerator:XML文件
daoGenerator:放置接口和DAO的代码

 

你需要做的是替换一些???:
1. 填写driverClass(jdbc驱动,例如oracle的就是oracle.jdbc.driver.OracleDriver)
2. 填写connectionURL(连接字符串,例如oracle的就是jdbc:oracle:thin:@192.168.0.246:1521:test)
3. 填写classPathEntry的location(jdbc驱动jar包的位置,例如E:/project/ibatistest/WebContent/WEB-INF/lib/ojdbc14.jar)
4. 填写javaModelGenerator,生成的DTO(java model 类)
    targetPackage:目标包的位置,如 com.test.dto
    targetProject:目标工程名称,填写配置文件所在的eclipse工程名
5. 填写sqlMapGenerator ,生成的xml sqlmap的相关配置
    targetPackage:目标位置,如 com.test.sqlmap
    targetProject:目标工程名称,填写配置文件所在的eclipse工程名
6. 填写daoGenerator ,生成的DAO的相关配置
    type:生成的dao实现的类型,如果你使用spring的话写SPRING,否则写IBATIS
    targetPackage:目标位置,如 com.test.dao
    targetProject:目标工程名称,填写配置文件所在的eclipse工程名
7. 配置相关数据库的表
    schema:数据库schema,oracle就是填写数据库的用户名
    tableName:表名

xml 代码

  1. <columnOverride column="???" property="???" />  


     可以先不用配置,删除就可以了

下面开始生成:
在配置文件上点解右键,选择 “Generate iBatis Artifacts”
OK,看看生成了什么吧!