`
高级java工程师
  • 浏览: 395982 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

myeclipse 安装 ibatis 插件 自动生成java代码

阅读更多
一.安装插件
从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的代码

 

如:

 

<?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.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/webbas?characterEncoding=gbk" userId="root" password="111111" >
      <classPathEntry location="E:/chenweixian/workspace20120309/generalIbatisCode/WebRoot/WEB-INF/lib/mysql-connector-java-5.1.16-bin.jar" />
    </jdbcConnection>
    <javaModelGenerator targetPackage="com.chen.domain.bean" targetProject="generalIbatisCode" />
    <sqlMapGenerator targetPackage="com.chen.domain.dao.impl.ibatis" targetProject="generalIbatisCode" />
    <daoGenerator targetPackage="com.chen.domain.dao" targetProject="generalIbatisCode" type="GENERIC-CI" />
    <table schema="aa" tableName="aa">
      
    </table>
  </abatorContext>
</abatorConfiguration>


注意:schema="aa" 没用就去除吧。targetProject="generalIbatisCode" 是工程名
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics