mybatis-gen自动生成Mapper中加入分页 (MySQL和Oracle)
2014-03-19 15:26
411 查看
MySQL较为简单,由于有limit关键字可用,需要定义的是分页起始偏移offset和分页大小size
这里参考:http://www.cnblogs.com/AloneSword/p/3412236.html
在Example类中添加offset和size两个变量,及get/set方法。
再在Mapper中的selectByExample最后添加
例如:TestMapper.xml
Oracle的就麻烦一点,这里使用Oracle自带的行号rownum,需要定义最大行号maxrow和最小行号minrow
参考Oracle分页语句:http://blog.163.com/yongqi0408@126/blog/static/4251263220087432522770/
在Example类中添加maxrow和minrow两个变量,及get/set方法。
再修改Mapper中的selectByExample如下:
使用方法:
这里参考:http://www.cnblogs.com/AloneSword/p/3412236.html
在Example类中添加offset和size两个变量,及get/set方法。
再在Mapper中的selectByExample最后添加
<if test="offset !=0 or size!=0"> limit #{offset},#{size} </if>
例如:TestMapper.xml
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.example.TestExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from TEST
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
<if test="offset !=0 or size!=0"> limit #{offset},#{size} </if>
</select>
Oracle的就麻烦一点,这里使用Oracle自带的行号rownum,需要定义最大行号maxrow和最小行号minrow
参考Oracle分页语句:http://blog.163.com/yongqi0408@126/blog/static/4251263220087432522770/
在Example类中添加maxrow和minrow两个变量,及get/set方法。
再修改Mapper中的selectByExample如下:
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.example.TestExample" > select * from ( select t1.*, rownum r from ( select <if test="distinct" > distinct </if> <include refid="Base_Column_List" /> from TEST <if test="_parameter != null" > <include refid="Example_Where_Clause" /> </if> <if test="orderByClause != null" > order by ${orderByClause} </if> ) t1 <if test="maxrow != 0"> where rownum <= ${maxrow} </if> ) t2 where r > ${minrow} </select>
使用方法:
TestExample example = new TestExample(); example.createCriteria(); example.setOrderByClause("TS DESC"); // TS是表中的时间戳列,这里按照时间降序排列 example.setMaxrow(maxrow); example.setMinrow(minrow); testMapper.selectByExample(example);
相关文章推荐
- 简单两步快速学会使用Mybatis-Generator自动生成entity实体、dao接口和简单mapper映射(用mysql和oracle举例)
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- tigercode是一款自动代码生产工具,支持springmvc+spring+mybatis或springmvc+spring+hibernate框架生成,数据库支持mysql ,oracle
- MyBatis 3 自动生成 主键 针对不同的数据库(oracle/sqlserver/mysql)
- mybatis 代码生成工具支持oracle mysql 分页
- spring和mybatis集成,自动生成model、mapper,增加mybatis分页功能
- springboot和mybatis集成,自动生成model、mapper,增加mybatis分页功能
- 使用Mybatis-Generator自动生成entity实体、dao接口以及mapper映射文件
- mysql根据数据库自动生成实体(dto,service,impl,mybatis,xml)
- 利用MyBatis Generator自动生成DO&DAO&mapper
- Mybatis MapperScannerConfigurer 自动扫描 将Mapper接口生成代理注入到Spring - 大新博客 - 推酷 - 360安全浏览器 7.1
- Mybatis插件自动生成mapper.xml和dao
- 在Oracle与mysql中自动生成uuid
- 自动生成mybatis的model,mapper,xml工具的使用
- iBatis自动生成的主键 (Oracle,MS Sql Server,MySQL)
- maven + mybatis 自动生成所需pojo、dao、mapper
- 使用mybatis的generator自动生成po及mapper映射文件