最近在项目中用到ibator1.2.1,但是感觉其自动生成的代码不能满足自己的需要,在网上找了资料:
1.
eclipse ibabis代码生成插件abator功能扩展
2.
aquan198163 写道 可以用iBatis的include标签设计类似模板的东西,简化分页sql
自己下载代码进行了相关扩展:
1.支持Oracle、MySQL分页
2.在生成的example类增加了Oracle、MySQL分页的相关字段
0.3版本:
增加了控制生成oracle分页和mysql分页的属性(原来是都生成)
<!--
<table tableName="BROWSELOGS" enableMysqlPagination="true">
<table tableName="BROWSELOGS" enableOraclePagination="false" >
-->
<table tableName="BROWSELOGS">
<columnOverride column="ID" javaType="Integer" />
<columnOverride column="VISITOR" javaType="Integer" />
<columnOverride column="DOTIME" jdbcType="Timestamp" />
</table>
当然这个时候,xml会报错,因为你引用的是网络上面的dtd("http://ibatis.apache.org/dtd/ibator-config_1_0.dtd"),不用理会,一样可以生成,如果都不填写,就是都不生成。
建议在ibatorContext加上
Ibatis2Java5:
<classPathEntry location="D:\UserLibraries\Oracle10g_driver.jar" />
<ibatorContext id="context" targetRuntime="Ibatis2Java5" >
完整版的配置:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE ibatorConfiguration PUBLIC "-//Apache Software Foundation//DTD Apache iBATIS Ibator Configuration 1.0//EN" "http://ibatis.apache.org/dtd/ibator-config_1_0.dtd" >
<ibatorConfiguration>
<classPathEntry location="D:\UserLibraries\mysql-connector-java-5.1.12-bin.jar" />
<ibatorContext id="context1" targetRuntime="Ibatis2Java5">
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/demo" userId="root"
password="aaa" />
<javaModelGenerator targetPackage="com.ibatis.pojo"
targetProject="test" />
<sqlMapGenerator targetPackage="com.ibatis.sqlmap"
targetProject="test" />
<daoGenerator targetPackage="com.ibatis.dao"
targetProject="test" type="SPRING" />
<table tableName="ueye_account" enableMysqlPagination="true">
<columnOverride column="ID" javaType="Integer" />
<columnOverride column="VISITOR" javaType="Integer" />
<columnOverride column="DOTIME" jdbcType="Timestamp" />
</table>
</ibatorContext>
</ibatorConfiguration>
0.2版本增加了:
4个list的set方法:
protected List criteriaWithoutValue;
protected List criteriaWithSingleValue;
protected List criteriaWithListValue;
protected List criteriaWithBetweenValue;
原来的方法里面没有set。只有get方法,我觉得有时候我不知道传入的是哪个字段,要自己定义一个条件不知道怎么放进去,我就想法先取出list,在set进去,如下:
// //过滤条件,仿造的是example类中的情况
// Criteria criteria=example.createCriteria();
// //得到example里面的list
// List<Object> listSingle=criteria.getCriteriaWithSingleValue();
// //再把它注入回去
// criteria.setCriteriaWithSingleValue(this.processFilterInfo(listSingle, sigma.getFilterInfo()));
processFilterInfo方法:
public List<Object> processFilterInfo(List<Object> listSingle,List<FilterInfo> filterInfos){
for (int i = 0; i < filterInfos.size(); i++) {
String columnId=filterInfos.get(i).getColumnId();
String logic=filterInfos.get(i).getLogic();
String value=filterInfos.get(i).getValue();
if(logic.equalsIgnoreCase("equal")){
Map<String,Object> map = new HashMap<String,Object>();
map.put("condition", columnId+" =");
map.put("value", value);
listSingle.add(map);
}else if(logic.equalsIgnoreCase("notequal")){
Map<String,Object> map = new HashMap<String,Object>();
map.put("condition", columnId+" <>");
map.put("value", value);
listSingle.add(map);
清单一(修改的相关类):
org.apache.ibatis.ibator.generator.ibatis2.sqlmap---SqlMapGenerator
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements---OraclePaginationHeadGenerator
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements---OraclePaginationTailGenerator
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements---MysqlPaginationLimitGenerator
org.apache.ibatis.ibator.generator.ibatis2.model---ExampleGenerator
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements---SelectByExampleWithBLOBsElementGenerator
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements---SelectByExampleWithoutBLOBsElementGenerator
org.apache.ibatis.ibator.api.dom.java---FullyQualifiedJavaType
搜索“增加开始”或者“增加结束”就能找到修改的地方
SQL_MAP.xml部分:
<!-- oracle 分页头 -->
<sql id="oracle_Pagination_Head" >
<dynamic >
<isNotEmpty property="oracleStart" >
<isNotEmpty property="oracleEnd" >
<![CDATA[select * from ( select row_.*, rownum rownum_ from ( ]]>
</isNotEmpty>
</isNotEmpty>
</dynamic>
</sql>
<!-- oracle 分页尾 -->
<sql id="oracle_Pagination_Tail" >
<dynamic >
<isNotEmpty property="oracleStart" >
<isNotEmpty property="oracleEnd" >
<![CDATA[) row_ where rownum <= #oracleEnd# ) where rownum_ > #oracleStart#]]>
</isNotEmpty>
</isNotEmpty>
</dynamic>
</sql>
<!-- MySQL 分页 -->
<sql id="mysql_Pagination_Limit" >
<dynamic >
<isNotEmpty property="mysqlOffset" >
<isNotEmpty property="mysqlLength" >
<![CDATA[ limit #mysqlOffset# , #mysqlLength# ]]>
</isNotEmpty>
</isNotEmpty>
</dynamic>
</sql>
<select id="ibatorgenerated_selectByExample" resultMap="ibatorgenerated_BaseResultMap" parameterClass="com.ibatis.pojo.GoodsExample" >
<!-- 增加oracle分页头部 -->
<include refid="oracle_Pagination_Head" />
select id, name, stand, money, leavings, orders
from goods
<isParameterPresent >
<include refid="goods.ibatorgenerated_Example_Where_Clause" />
<isNotNull property="orderByClause" >
order by $orderByClause$
</isNotNull>
</isParameterPresent>
<!-- 增加oracle分页尾部 -->
<include refid="oracle_Pagination_Tail" />
<!-- 增加MySQL分页 -->
<include refid="mysql_Pagination_Limit" />
</select>
Example类部分:
public class GoodsExample {
protected String orderByClause;
private Integer oracleStart;
private Integer oracleEnd;
private Integer mysqlOffset;
private Integer mysqlLength;
protected List oredCriteria;
public GoodsExample() {
oredCriteria = new ArrayList();
}
}
附件为ibator1.2.1插件,直接复制到Eclipse的dropins文件夹下即可
分享到:
相关推荐
自动生成dto\dao\xml 自带批处理自动生成程序
去除了注释、去除Example方法及去除生成的id前面的“ibatorgenerated_”
eclipse的ibatis代码生成器,最新版ibator 1.2.1
用户ibatis自动成才代码的一种工具,减少开发人员的工作量。
NULL 博文链接:https://guoba6688-sina-com.iteye.com/blog/1098212
ibatis代码自动生成工具Eclipse插件,已进行优化处理,不生成注释和精简dao方法,亲测可用
ibator插件优化的jar包,安装完ibator后,将eclipse\plugins\org.apache.ibatis.ibator.core_1.2.1下的jar包替换即可。
直接丢到eclipse的plugins目录下就可以了,在一些公司下载不了的地方,方便使用
iBATOR is a code generator for iBATIS.
将邮件中附件的Ibator插件压缩文件IbatorForEclipse1.2.1.zip并解压到本地磁盘如:解压到”ibator文件夹”。然后按以下步骤安装: 1.1 选择Help—>Software Updates—>Add/Remove Software…;如下图所示
ibator1.2.2多了点功能,具体可以百度,重新编译了下,生成注释去掉了
eclipse的集成插件,ibator.jar,可以直接mybatis导表,图形化展示,简单易用,直接放到eclipse的plugin文件夹下即可
Ibator is a code generator for iBATIS. Ibator will introspect a database table (or many tables) and will generate iBATIS artifacts that can be used to access the table(s). This abates some of the ...
ibator教学视频,手把手教你使用ibator
ibator相对于hibernate框架能完全自主编写sql代码,同时又有hibernate便于管理的优点,是非常理想的持久层技术
做SSI项目时,Ibator映射出来的内容实在太多了,有很多内容都用不上,参考Ibator的结构,实现对基本字段和方法的映射!
使用数据库的注释,不用自带的注释 http://blog.csdn.net/tiantangpw/article/details/43489817 运行命令 java -jar ibator.jar -configfile ibatorConfig.xml -overwrite >>ibator.log
此项目通过对ibator的改造,通过执行cmd命令自动生成sql与Dao,大大提高开发效率
ibator-config_1_1.dtd ibator用
Ibatis 生成器 Ibator 的 API 文档