需求说明:为用户管理之查询用户列表功能增加分页实现      列表结果按照创建时间降序排列

/**
* 需求说明:为用户管理之查询用户列表功能增加分页实现 列表结果按照创建时间降序排列
* @param roleids
* @return
*/
public List<User> getUserListByPage(@Param("usercode")String usercode,@Param("userName")String userName,@Param("userRole")Integer userRole,@Param("pageSize")Integer pageSize,@Param("currentPage")Integer currentPage);

<!--分页查询 -->
<select id="getUserListByPage" resultMap="userList" >
  select * from smbms_user a,smbms_role r where 1=1 and a.userrole=r.id
    <if test=" userName!=null and userName!='' "> and a.userName like concat('%',#{userName},'%') </if>
    <if test=" userRole!=null and userRole!='' "> and a.userrole=#{userRole} </if>
  order by a.creationdate desc limit #{currentPage},#{pageSize}
</select>

<!-- 当数据库中的字段信息与对象的属性不一致时需要通过resultMap来映射 -->
<resultMap type="User" id="userList">
  <result property="id" column="id"/>
  <result property="userCode" column="userCode"/>
  <result property="userName" column="userName"/>
  <result property="phone" column="phone"/>
  <result property="birthday" column="birthday"/>
  <result property="gender" column="gender"/>
  <result property="userRole" column="userRole"/>
  <!-- <result property="userRoleName" column="roleName"/> -->
</resultMap>

     //mybatis分页
@Test
public void testGetUserListByPage(){
SqlSession sqlSession = null;
String usercode="";
String userName="";
Integer userRole=3;
Integer pageSize=5;
Integer currentPage=0;//mysql数据库默认起步是从0开始
List<User> userListShow=new ArrayList<User>();
try { sqlSession = MyBatisUtil.createSqlSession();
userListShow = sqlSession.getMapper(UserMapper.class).getUserListByPage(usercode,userName,userRole,pageSize,currentPage); } catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
MyBatisUtil.closeSqlSession(sqlSession);
}
for(User user: userListShow){
logger.debug("testGetUserListByPage UserCode: " + user.getUserCode() + " and UserName: " + user.getUserName()+"and userRole:"+user.getUserRole());
} }

运行结果:

 [DEBUG] 2019-12-22 17:53:33,894 cn.smbms.dao.user.UserMapper.getUserListByPage - ==>  Preparing: select * from smbms_user a,smbms_role r where 1=1 and a.userrole=r.id and a.userrole=? order by a.creationdate desc limit ?,?
[DEBUG] 2019-12-22 17:53:33,911 cn.smbms.dao.user.UserMapper.getUserListByPage - ==> Parameters: 3(Integer), 0(Integer), 5(Integer)
[DEBUG] 2019-12-22 17:53:33,925 org.apache.ibatis.transaction.jdbc.JdbcTransaction - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@4a738d08]
[DEBUG] 2019-12-22 17:53:33,925 org.apache.ibatis.transaction.jdbc.JdbcTransaction - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@4a738d08]
[DEBUG] 2019-12-22 17:53:33,925 org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 1249086728 to pool.
[DEBUG] 2019-12-22 17:53:33,926 cn.smbms.dao.user.UserMapperTest - testGetUserListByPage UserCode: sunxing and UserName: 孙兴and userRole:3
[DEBUG] 2019-12-22 17:53:33,926 cn.smbms.dao.user.UserMapperTest - testGetUserListByPage UserCode: zhangchen and UserName: 张晨and userRole:3
[DEBUG] 2019-12-22 17:53:33,926 cn.smbms.dao.user.UserMapperTest - testGetUserListByPage UserCode: dengchao and UserName: 邓超and userRole:3
[DEBUG] 2019-12-22 17:53:33,926 cn.smbms.dao.user.UserMapperTest - testGetUserListByPage UserCode: zhaoyan and UserName: 赵燕and userRole:3
[DEBUG] 2019-12-22 17:53:33,926 cn.smbms.dao.user.UserMapperTest - testGetUserListByPage UserCode: sunlei and UserName: 孙磊and userRole:3

mybatis框架的分页功能的更多相关文章

  1. Mybatis Generator实现分页功能

    Mybatis Generator实现分页功能 分类: IBATIS2013-07-17 17:03 882人阅读 评论(1) 收藏 举报 mybatisibatisgeneratorpage分页 众 ...

  2. SpringBoot集成Mybatis并具有分页功能PageHelper

    SpringBoot集成Mybatis并具有分页功能PageHelper   环境:IDEA编译工具   第一步:生成测试的数据库表和数据   SET FOREIGN_KEY_CHECKS=0;   ...

  3. DRF框架中分页功能接口

    目录 DRF框架中分页功能接口 DRF框架中分页功能接口 一.在框架中提供来三个类来实现分页功能,PageNumberPagination.LimitOffsetPagination.CursorPa ...

  4. java ssm框架实现分页功能 (oracle)

    java web 实现分页功能 使用框架:ssm 数据库:oracle 话说 oracle 的分页查询比 mysql 复杂多了,在这里简单谈一下: 查询 前十条数据: SELECT * FROM( S ...

  5. sql,mybatis,javascript分页功能的实现

    用三种不同的方法实现多数据的分页功能.原生sql和mybatis的操作需要每次点击不同页数时都发送http请求,进行一次数据库查询,如果放在前端页面写js语句则不需要每次都请求一次,下面是三种不同的方 ...

  6. mybatis框架中分页的实现

    2.分页的实现? 分页的时候考虑的问题: 分页的大小,分页的索引. 比如:分页的大小为10,分页的起始索引为1(索引从1开始) 第一页:1到10.    起始行号: (页的索引-1)*分页大小+1 结 ...

  7. mybatis如何实现分页功能?

    1)原始方法,使用limit,需要自己处理分页逻辑: 对于mysql数据库可以使用limit,如: select * from table limit 5,10; --返回6-15行 对于oracle ...

  8. 从 0 开始手写一个 Mybatis 框架,三步搞定!

    阅读本文大概需要 3 分钟. MyBatis框架的核心功能其实不难,无非就是动态代理和jdbc的操作,难的是写出来可扩展,高内聚,低耦合的规范的代码. 本文完成的Mybatis功能比较简单,代码还有许 ...

  9. SpringBoot+Mybatis+PageHelper实现分页

    SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...

随机推荐

  1. oracle-报错 RMAN-03002,RMAN-06172

    RMAN> restore standby controlfile from "/data/oracle/contral.ctl"; Starting restore at ...

  2. 团队作业第五次—项目冲刺-Day7

    Day7 part1-SCRUM: 项目相关 作业相关 具体描述 所属班级 2019秋福大软件工程实践Z班 作业要求 团队作业第五次-项目冲刺 作业正文 hunter--冲刺集合 团队名称 hunte ...

  3. [Powershell]使用Msbuild构建基于.NET Framework的WebAPI项目

    查找最高版本的MsBuildTools. 清理缓存垃圾. 还原NuGet包. 构建解决方案. 按项目发布程序到本地. 按项目ZIP打包. <# .NOTES ================== ...

  4. 纯 css 打造一个小提示 tooltip

    最后编辑:2019/11/26 前 无意间在寻找资料时候,发现一个不错的小提示,查看源码竟然是纯手工 css 编写(文章底部参考链接). 效果 使用的特性 css2 中的 attr 函数,所以现在(2 ...

  5. day06——小数据池、深浅拷贝、集合

    day06 小数据池 小数据池--缓存机制(驻留机制),只是一种规格,不会实际的开辟一个空间 == 判断两边内容是否相等 ***** # a = 10 # b = 10 # print(a == b) ...

  6. ListView 实现进度条显示

    代码参考互联网,本人在Win10 + Delphi 10.3.2 社区版中测试通过,现将测试通过的代码分享如下: unit Unit1; interface uses Winapi.Windows, ...

  7. linux 通过tar直接打包方式 迁移oracle的软件包环境:rdbms/lib/config.c

    step1.修改sysctl.conf step2.修改ulimit.conf step3.打包源oracle安装包 step4.通过id{oracle的安装运行用户} 获取安装oracle的[ORA ...

  8. python爬虫—爬取英文名以及正则表达式的介绍

    python爬虫—爬取英文名以及正则表达式的介绍 爬取英文名: 一.  爬虫模块详细设计 (1)整体思路 对于本次爬取英文名数据的爬虫实现,我的思路是先将A-Z所有英文名的连接爬取出来,保存在一个cs ...

  9. leetcode求峰值,js实现

    原题: 最开始是照着提示的思路进行,中规中矩,用时64ms  /** * @param {number[]} nums * @return {number} */var findPeakElement ...

  10. python plotly画柱状图

    代码 import pandas as pd import numpy as np import plotly.plotly as py import plotly.graph_objs as go ...