一.安装插件
从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="项目名称" />
<sqlMapGenerator targetPackage="map层包名称" targetProject="项目名称" />
<daoGenerator targetPackage="dao层包名称" targetProject="项目名称" type="IBATIS" />
<table schema="模式名" tableName="表名" catalog="数据库名">一定要写上,不然会报错的。
</table>
</abatorContext>
</abatorConfiguration>
在abatorCsonfig.xml上点击鼠标右键,选择Generate iBATIS Artifact,在src目录下会生成model、map、dao三个目录,文件也建立好了。
javaModelGenerator:我们常说的ValueObject
sqlMapGenerator:XML文件
daoGenerator:放置接口和DAO的代码
写一个sqlserver 的例子给大家看看:
我的项目名字是IbatisTest
<?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="com.microsoft.jdbc.sqlserver.SQLServerDriver" connectionURL="jdbc:sqlserver://localhost:1433;DatabaseName=sunlight" userId="sa" password="" >
<classPathEntry location="E:/IbatisTest/lib/mssqlserver.jar" />
<classPathEntry location="E:/IbatisTest/lib/msutil.jar" />
<classPathEntry location="E:/IbatisTest/lib/msbase.jar" />
</jdbcConnection>
<javaModelGenerator targetPackage="com.yzsunlight.model" targetProject="IbatisTest" />
<sqlMapGenerator targetPackage="com.yzsunlight.maps" targetProject="IbatisTest" />
<daoGenerator targetPackage="com.yzsunlight.dao" targetProject="IbatisTest" type="IBATIS" />
<table tableName="stu" schema="dbo" catalog="sunlight">
</table>
</abatorContext>
</abatorConfiguration>