MyBatisPlus分页
生活随笔
收集整理的這篇文章主要介紹了
MyBatisPlus分页
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建MyBatisPlus配置類
package com.yootk.provider.config;import com.baomidou.mybatisplus.annotation.DbType; 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;@Configuration public class MyBatisPlusConfig { // MybatisPlus配置類@Beanpublic MybatisPlusInterceptor getMybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 攔截器interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 分頁處理return interceptor;} }創建IDeptDAO數據接口
package com.yootk.provider.dao;import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.yootk.provider.vo.Dept; import org.apache.ibatis.annotations.Mapper;@Mapper public interface IDeptDAO extends BaseMapper<Dept> { // DAO接口開發完成 }在生產端需要提供有業務接口的實現子類
@Service public class DeptServiceImpl implements IDeptService {@Autowiredprivate IDeptDAO deptDAO;@Overridepublic Map<String, Object> split(int currentPage, int lineSize, String column, String keyword) {QueryWrapper<Dept> wrapper = new QueryWrapper<>();wrapper.like(column, keyword); // 設置模糊查詢操作int count = this.deptDAO.selectCount(wrapper); // 統計個數// 實現數據的查詢處理IPage<Dept> page = this.deptDAO.selectPage(new Page<>(currentPage, lineSize, count), wrapper);Map<String, Object> map = new HashMap<>(); // 包裝返回結果map.put("allDepts", page.getRecords()); //數據記錄map.put("allRecorders", page.getTotal()); //總數map.put("allPages", page.getPages()); //頁數return map;} }總結
以上是生活随笔為你收集整理的MyBatisPlus分页的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑更改了硬件或软件开不了机了怎么办?
- 下一篇: Ribbon 客户端负载均衡