import com.baomidou.mybatisplus.annotation.DbType;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
@Configuration
public class MyBatisPlusPageConfig {
@Bean
public PaginationInterceptor mybatisPlusInterceptor() {
// 1、创建分页插件
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 2、添加分页插件
return paginationInterceptor;
}
}
<!--mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>
插件的使用如下:
@Override
public List<SessionChatRecordEntity> getSessionRecordByPageNo(Integer sessionId, Integer pageNo, Integer size) {
// 创建一个分页对象
IPage<SessionChatRecordEntity> page = new Page<>(pageNo, size);
// 查询条件:根据sessionId查询,并按createTime降序排列
IPage<SessionChatRecordEntity> resultPage = baseMapper.selectPage(page, new QueryWrapper<SessionChatRecordEntity>()
.eq("session_id", sessionId)
.orderByAsc("session_chat_id"));
// 返回分页结果中的数据列表
return resultPage.getRecords();
}