实用mysql分页的ibator

实用mysql分页的ibator

适用mysql分页的ibator

ibator生成的ibatis文件不带分页功能(或我没找到)。

最近研究了ibator源码,改造了下,适用mysql的分页。

大家可下载附件:ibator-guoba.rar

?

原理:

1、在生成的sql_map中加入limit语句,判断Example类中的pager是否为空。

2、生成BasePager类,含有pageStart,pagerEnd两个属性和方法,用于examplo继承。

3、在生成Examplo时加上继承BasePager

4、在DAOImpl中,对非select方法,接受example参数的方法判断不要传入pager(delete,update,insert)

?

生成ibatis文件:

1、写ibator.xml,配置数据源,dao, Model,sqlmap

2、点击 build.bat

java -jar ibator-guoba.jar -configfile ibator.xml -overwrite

3、生成的代码在 ibator-guobaIbatorTestProjectsrc? 下

?

?

程序中如何使用分页:

?

ConfigExample example = new ConfigExample();
example.createCriteria()..........;
example.setPageStart(2);
example.setPageEnd(10);
configDAO.selectByExample(example);

?

在非select时,置入pager时,会抛出参数异常。

?

源码介绍:

?

1、源码在ibator-guoba-src.zip中

2、生成BasePager类的代码在:

org.apache.ibatis.ibator.generator.ibatis2.IntrospectedTableIbatis2Java2Impl.getGeneratedJavaFiles()

?

3、生成Example加上继承BasePager

org.apache.ibatis.ibator.generator.ibatis2.model.ExampleGenerator

?4、在DAO中检验非select方法不允许传入pager

org.apache.ibatis.ibator.generator.ibatis2.dao.elements.AbstractDAOElementGenerator.getExamplePagerCheckContent();
org.apache.ibatis.ibator.generator.ibatis2.dao.DAOGenerator

?

?

5、在sql_map中加入limit语句

org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements.ExampleWhereClauseElementGenerator.addElements

?

实用mysql分页的ibator

相关文章:

你感兴趣的文章:

标签云: