mybatis中的分页

来源:互联网 发布:管家婆软件操作流程 编辑:程序博客网 时间:2024/05/29 11:44

一、使用RowBounds



映射文件:

<?xml version="1.0" encoding="UTF-8" ?>  <!DOCTYPE mapper PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"       "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd"><!-- 命名空间为一个字符串,加以区分xml中各个元素 --><!-- 分页查询cost表2-4条数据 --><mapper namespace="cost">  <resultMap type="entity.Cost" id="costMap"><result property="costId" column="cost_id" /><result property="baseDuration" column="base_duration" /><result property="baseCost" column="base_cost" /><result property="unitCost" column="unit_cost" /><result property="costType" column="cost_type" />  </resultMap>  <select id="pageFind" resultMap="costMap">    SELECT * FROM cost ORDER BY cost_id  </select>  <!--   SELECT * FROM(      SELECT ROWNUM rw,c.* FROM        (SELECT * FROM cost ORDER BY cost_id) c    )   --></mapper>

测试代码:

//对表cost进行分页查询@Testpublic void test8(){RowBounds bounds = new RowBounds(3,2);//使用RowBounds的时候,若没有参数则写nullList<Cost> list = session.selectList("cost.pageFind",null,bounds);for(Cost c : list){System.out.println(c);}}

测试结果:

Cost [costId=4, name=10.5元套餐, baseDuration=200, baseCost=10.5, unitCost=0.1, status=0, descr=10.5元200小时/月,超出部分0.1元/时, creatime=2017-06-12 14:38:10.0, startime=null, costType=2]
Cost [costId=5, name=计时收费, baseDuration=null, baseCost=null, unitCost=0.5, status=0, descr=0.5元/时,不使用不收费, creatime=2017-06-12 14:38:11.0, startime=null, costType=3]






原创粉丝点击