mybatis-gen自动生成Mapper中加入分页 (MySQL和Oracle)
来源:互联网 发布:类似傲风 知乎 编辑:程序博客网 时间:2024/05/16 11:22
MySQL较为简单,由于有limit关键字可用,需要定义的是分页起始偏移offset和分页大小size
这里参考: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);
0 0
- mybatis-gen自动生成Mapper中加入分页 (MySQL和Oracle)
- mybatis 自动生成 mapper
- mybatis自动生成entity,dao和mapper
- MyBatis-自动生成pojo、mapper和mapper.xml
- 简单两步快速学会使用Mybatis-Generator自动生成entity实体、dao接口和简单mapper映射(用mysql和oracle举例)
- mybatis + maven 自动生成mapper
- mybatis自动生成mapper.xml和接口实体类工具
- mybatis反转自动生成dao、实体类和mapper.xml
- 使用mybatis-generator自动生成dao、model和mapper
- Eclipse+MyBatis自动生成Mapper和实体还有对应sqlxml
- 使用MyBatis Generator自动生成实体、mapper和dao层
- Mybatis自动生成实体类、mapper.xml和dao
- mybatis自动生成mapper+pojo(mapper接口和普通dao)
- Mybatis自动生成Mapper工具配置文件
- mybatis自动生成mapper.xml的方法
- mybatis自动生成mapper,dao,映射文件
- mybatis自动生成mapper,dao,映射文件
- mybatis自动生成mapper xml 映射 文件
- JDBC常见面试题集锦-->链接整理
- 音频的切割
- 联通出4G iPhone 5S(A1528)用不了
- android app中的给应用评分
- mysql 字段类型
- mybatis-gen自动生成Mapper中加入分页 (MySQL和Oracle)
- 浙江大学PAT---Basic Level---1010----一元多项式求导
- 对2014年北京卷高考《考试说明》的解读
- Cracking the coding interview--Q12.7
- 在Qt编写的程序中打开文件夹
- js锁屏
- Spring 3.0 注解注入详解
- 数据中心演变历程:从大型机到云计算
- ios常见的四种保存数据方法