Springboot+Mybatis+PageHelper 分页、排序

本文详细介绍如何在SpringBoot项目中使用Mybatis和PageHelper进行数据分页和排序操作,包括配置步骤、PageHelper和Mybatis两种排序方法的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Springboot+Mybatis+PageHelper 分页、排序

升序 asc、降序 desc

<!-- 继承 spring boot 父包-->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.1.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent> 		
<!-- springboot分页插件,pagehelper1.2.3与 springboot1.5不兼容
必须使用pagehelper的spring starter,才能无配置启动使用pagehelper,千万别引用错-->
    <dependency>
            <groupId>com.github.pagehelper</groupId>
	    <artifactId>pagehelper-spring-boot-starter</artifactId>
	    <version>1.2.2</version>
   </dependency>

方法一:PageHelper排序

String orderBy = "sort asc"; //PageHelper方法 (排序字段 空格 排序方式)(注意:都是数据库中的字段,不是实体pojo的)
PageHelper.startPage(page, size, orderBy);
List<TbDictDetail> selectByExample = dictDetailMapper.selectByExample(null);

方法二:Mybatis排序

String orderBy = "sort asc,sort2 desc"; //(排序字段 空格 排序方式,排序字段 空格 排序方式)
PageHelper.startPage(page, size, orderBy);
TbDictDetailExample example = new TbDictDetailExample();
example.setOrderByClause(orderBy); //排序
List<TbDictDetail> selectByExample = dictDetailMapper.selectByExample(example);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值