适用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
org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements.ExampleWhereClauseElementGenerator.addElements
?