mybatis框架的分页功能
需求说明:为用户管理之查询用户列表功能增加分页实现 列表结果按照创建时间降序排列
/**
* 需求说明:为用户管理之查询用户列表功能增加分页实现 列表结果按照创建时间降序排列
* @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框架的分页功能的更多相关文章
- Mybatis Generator实现分页功能
Mybatis Generator实现分页功能 分类: IBATIS2013-07-17 17:03 882人阅读 评论(1) 收藏 举报 mybatisibatisgeneratorpage分页 众 ...
- SpringBoot集成Mybatis并具有分页功能PageHelper
SpringBoot集成Mybatis并具有分页功能PageHelper 环境:IDEA编译工具 第一步:生成测试的数据库表和数据 SET FOREIGN_KEY_CHECKS=0; ...
- DRF框架中分页功能接口
目录 DRF框架中分页功能接口 DRF框架中分页功能接口 一.在框架中提供来三个类来实现分页功能,PageNumberPagination.LimitOffsetPagination.CursorPa ...
- java ssm框架实现分页功能 (oracle)
java web 实现分页功能 使用框架:ssm 数据库:oracle 话说 oracle 的分页查询比 mysql 复杂多了,在这里简单谈一下: 查询 前十条数据: SELECT * FROM( S ...
- sql,mybatis,javascript分页功能的实现
用三种不同的方法实现多数据的分页功能.原生sql和mybatis的操作需要每次点击不同页数时都发送http请求,进行一次数据库查询,如果放在前端页面写js语句则不需要每次都请求一次,下面是三种不同的方 ...
- mybatis框架中分页的实现
2.分页的实现? 分页的时候考虑的问题: 分页的大小,分页的索引. 比如:分页的大小为10,分页的起始索引为1(索引从1开始) 第一页:1到10. 起始行号: (页的索引-1)*分页大小+1 结 ...
- mybatis如何实现分页功能?
1)原始方法,使用limit,需要自己处理分页逻辑: 对于mysql数据库可以使用limit,如: select * from table limit 5,10; --返回6-15行 对于oracle ...
- 从 0 开始手写一个 Mybatis 框架,三步搞定!
阅读本文大概需要 3 分钟. MyBatis框架的核心功能其实不难,无非就是动态代理和jdbc的操作,难的是写出来可扩展,高内聚,低耦合的规范的代码. 本文完成的Mybatis功能比较简单,代码还有许 ...
- SpringBoot+Mybatis+PageHelper实现分页
SpringBoot+Mybatis+PageHelper实现分页 mybatis自己没有分页功能,我们可以通过PageHelper工具来实现分页,非常简单方便 第一步:添加依赖 <depend ...
随机推荐
- Visual Studio 调试系列7 查看变量占用的内存(使用内存窗口)
系列目录 [已更新最新开发文章,点击查看详细] 在调试期间,“内存”窗口显示应用程序正在使用的内存空间. 调试器窗口(如监视窗口.自动窗口.局部变量窗口和快速监视对话框)显示变量,这些变量存储 ...
- Loj #3124. 「CTS2019 | CTSC2019」氪金手游
Loj #3124. 「CTS2019 | CTSC2019」氪金手游 题目描述 小刘同学是一个喜欢氪金手游的男孩子. 他最近迷上了一个新游戏,游戏的内容就是不断地抽卡.现在已知: - 卡池里总共有 ...
- addpath(),genpath()
clear all:clear clc: addpath(): 打开不在同一目录下的文件 addpath('sparse-coding');%sparse-coding,SIFT均表示路径,此目录下的 ...
- vertica ROS和WOS错误
频繁写入vertica,可能导致ROS和WOS错误.如下: java.sql.SQLTransientException: [Vertica][VJDBC](5065) ERROR: Too many ...
- springmvc项目转为springboot
说明 如果你的项目连maven项目都不是,请自行转为maven项目,在按照本教程进行. 本教程适用于spring+springmvc+mybatis+shiro的maven项目. 1.修改pom文件依 ...
- BCryptPasswordEncoder 判断密码是否相同
加密 BCryptPasswordEncoder encode = new BCryptPasswordEncoder(); encode.encode(password); 比较 matches(C ...
- Codeforces Global Round 3
Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...
- 1小时搞定vuepress快速制作vue文档/博客+免费部署预览
先来一下演示效果.和vue的官方文档几乎是一致的,页面内容都可自定义. 此教程部署后的效果预览. 在你跟着教程搭建好项目之后,你会收获: 快速搭建一个文档/博客,后期只需要修改markdown内容和导 ...
- SQL Server使用sp_executesql在存储过程中执行多个批处理
SQL Server中有些SQL语句只能在一个批处理里面完成,例如CREATE SCHEMA语句创建SCHEMA的时候,每个SCHEMA都需要在一个单独的批处理里面完成: CREATE SCHEMA ...
- c#对象深复制demo
public class Person : ICloneable { public string Name; object ICloneable.Clone() { return this.Clone ...