pageHelp分页
导入依赖必须是这个依赖
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
if (pageSize != null && pageSize != null) {
PageHelper.startPage(pageNo, pageSize);
}
//查询语句
List<Map<String, Object>> list = teamBuildingService.contactinformation(indexInstitution, regionCode);
if (pageNo != null && pageSize != null) {
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
return R.ok(pageInfo);
}
return R.ok(list);
if (pageSize != null && pageSize != null) {
PageHelper.startPage(pageNo, pageSize);
}
//查询语句
List<Map<String, Object>> list = teamBuildingService.contactinformation(indexInstitution, regionCode);
if (pageNo != null && pageSize != null) {
PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
return R.ok(pageInfo);
}
return R.ok(list);
mybaties 分页
package com.mjh.regie.config;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* 配置Mp 分页
*/
@Configuration
public class MybatiesPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor(){
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
return mybatisPlusInterceptor;
}
}
//构建分页构造器
Page pageInfo = new Page(page, pageSize);
//条件构造器
LambdaQueryWrapper<Employee> queryWrapper=new LambdaQueryWrapper();
if (name!=null) {
queryWrapper.like(Employee::getUsername,name);
}
//添加排序
queryWrapper.orderByDesc(Employee::getUpdateTime);
//分页
return R.success( employService.page(pageInfo,queryWrapper));
Page<NaturalReserve> page = new Page(
Optional.ofNullable(pageNo).orElse(1),
Optional.ofNullable(pageSize).orElse(5));
LambdaQueryWrapper<NaturalReserve> queryWrapper = new LambdaQueryWrapper<>();
//构建查询条件
queryWrapper.in(NaturalReserve::getDistCode, childrenIds)
.eq(NaturalReserve::getLevel, level)
.like(StringUtils.hasText(name), NaturalReserve::getName, name)
.orderByDesc(NaturalReserve::getName);
Page<NaturalReserve> result = naturalReserveMapper.selectPage(page, queryWrapper);
//返回数据
Map<String, Object> map = new HashMap<>();
map.put("pageNo", result.getCurrent());
map.put("pageSize", result.getSize());
map.put("total", result.getTotal());
map.put("data", result.getRecords());
return map;
自定义sql 配合mybaitesplus 分页
//虽然传入的是map 但是底层 加入 的list<Map>所以还是会查出来多条数据
Page<Map<String, Object>> page = new Page(
Optional.ofNullable(pageNo).orElse(1),
Optional.ofNullable(pageSize).orElse(5));
//自己的sql 语句
IPage<Map<String, Object>> list = naturalReserveMapper.pageList(page, regionCode, name, level);
//返回数据
Map<String, Object> map = new HashMap<>();
map.put("pageNo", list.getCurrent());
map.put("pageSize", list.getSize());
map.put("total", list.getTotal());
map.put("data", list.getRecords());
return map;