使用abator配置iBatis,管理数据库(以MySql为例)

参考:

http://blog.csdn.net/watson243671/archive/2010/01/02/5122385.aspx

帮助文档:

http://ibatis.apache.org/docs/tools/abator/

相信很多的朋友对使用iBatis管理数据库很不习惯,因为我们要手写代码,特别是dynamic query部分更是不知如何嵌套,而这些是可以用工具的!下面介绍一种最常用的!不废话了,直接上配置过程!

1、获得  http://ibatis.apache.org/abator.html 
     Eclipse可以自动的进行Update获取此Plugin,官方的安装步骤.

If you've already installed a prior version of Abator, simply run the Eclipse Install/Update tool and the new version will be found automatically.

 

If you've not already installed Abator, then you can use the built in Eclipse install support by following these steps:

 

Take the "Help>Software Updates>Find and Install" Menu Option 

Select the "Search for new features to install" radio button, press "Next" 

Press the "New Remote Site" button 

Enter the following information: 

Name: 

Abator for Eclipse Update Site 

URL: 

http://ibatis.apache.org/tools/abator

Press OK 

Check the box next to "Abator for Eclipse Update Site" 

Follow the remainder of the install wizard

  

2、安装好后将在New菜单中看到一个新的文件类型Abator for iBATIS Configuration File,此是Abator的配置文件,配置文件的详细说明见http://ibatis.apache.org/docs/tools/abator/ 
3、新建一个配置文件,进行修改,根据自己的实际需求进行修改 
关键点: 
1)jdbc connection,按照一般的配置即可,需要说明的是它需要指定访问JdbcDriver的classPathEntry,对于MsSqlServer而言,要将这三个jar文件均包含在内,否则会出现jdbc访问错误。 
2)配置三个Pakage 
3)配置表,此处需说明的是对于MsSqlServer不能写TableSchema,我初次指定TableSchema,结果未找到对应的表 
简单的配置如下,复杂的见配置文件的详细说明。示例配置文件如下 :

 

<?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 generatorSet="Java5">
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/anquanxitong"
userId="root" password="123456">
<classPathEntry location="C:\Documents and Settings\Administrator\Workspaces\MyEclipse\iBatisMysql\lib\mysql-connector-java-5.1.10-bin.jar" />
</jdbcConnection>
<javaModelGenerator targetPackage="com.agile.aqxt.model" targetProject="iBatisMysql" /> 
<sqlMapGenerator targetPackage="com.agile.aqxt.maps" targetProject="iBatisMysql" /> 
<daoGenerator targetPackage="com.agile.aqxt.dao" targetProject="iBatisMysql" type="GENERIC-SI" /> 


<table schema="anquanxitong" tableName="card_info">
<generatedKey column="card_id" sqlStatement="MYSQL" identity="true"  /> 
</table>
<table schema="anquanxitong" tableName="user_info">
<generatedKey column="id" sqlStatement="MYSQL" identity="true" /> 
</table>
<table schema="anquanxitong" tableName="user_sta">
<generatedKey column="user_id" sqlStatement="MYSQL" identity="true" /> 
</table>

</abatorContext>
</abatorConfiguration> 
 

4、右键单击配置文件,点击Generate iBatis Artifacts,生成文件。下面是生成后的项目文件。

使用abator配置iBatis,管理数据库(以MySql为例)

 

你可能感兴趣的:(eclipse,mysql,ibatis,配置管理,项目管理)