zoukankan      html  css  js  c++  java
  • ibatis自动生成

    对于IBatis应用最烦人的重复工作就是不停的写DAO,DTO,和xml文件里面的sqlmap,其实很多时候这些工作是重复而且无聊的。好在我们还 有abator (http://ibatis.apache.org/abator.html ),一个IBatis自动生成工具,他可以帮助你生成大量的DAO,DTO和sqlmap。
    如果你使用eclipse作为IDE那么事情就很简 单了(相信没有几个人不在用):
    安装Eclipse插件
    1. 要求eclipse3.1,jdk1.4以上
    2. 在eclipse上安装abator插件
        eclipse菜单栏 --> help --> Software Updates --> Find And Install...
        在弹出的对话框中选择 “Search for new features to install” 然后点击 “next”
        在对话框中点击按钮 New Remort Site... 在弹出的对话框中的URL输入框中填写 http://ibatis.apache.org/tools/abator ,Name输入框就随便写些什么了。
        点击Finish,安装插件,然后重新启动eclipse

    下面测试一下功能
    1. 新建一个java工程
    2. 在eclipse菜单栏中兴建一个 abator 配置文件
        File --> Abator for iBatis Configration File

    好的,我们完成了创建配置文件,下面打abator配置文 件,看看里面怎么去配置
    打开后内容基本上是这样

    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>    <!-- TODO: Add Database Connection Information -->  
        <jdbcConnection driverClass="???"  
            connectionURL="???"  
            userId="???"  
            password="???">  
          <classPathEntry location="???" />  
        </jdbcConnection>  
      
        <javaModelGenerator targetPackage="???" targetProject="???" />  
        <sqlMapGenerator targetPackage="???" targetProject="???" />  
        <daoGenerator type="IBATIS" targetPackage="???" targetProject="???" />  
      
        <table schema="???" tableName="???">  
          <columnOverride column="???" property="???" />  
        </table>  
      
      </abatorContext>  
    </abatorConfiguration>  

    你需要做的是替换一些???:
    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 代码<columnOverride column="???" property="???" />  


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

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

  • 相关阅读:
    python—9个基础常识-python小白入门系列
    学完Python,我决定熬夜整理这篇总结...
    Python中时间戳、时间字符串、时间结构对象之间的相互转化
    [Python3] 超级码力在线编程大赛初赛 第2场 题解
    利用人工智能算法让古代皇帝画像以及古代四大美女画像动起来(模仿偶像胡歌剧中角色表情动作
    python爬取酷我音乐(收费也可)
    Python基础入门:从变量到异常处理–阿里云天池
    python 使用 wechatsogou wkthmltopdf 导出微信公众号文章
    ASP.NET WebAPI 连接数据库
    从头开始一步一步实现EF6+Autofac+MVC5+Bootstarp极简的实现前后台ajax表格展示及分页实现
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606905.html
Copyright © 2011-2022 走看看