MyBatisPlus分页
生活随笔
收集整理的這篇文章主要介紹了
MyBatisPlus分页
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
創(chuàng)建MyBatisPlus配置類(lèi)
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配置類(lèi)@Beanpublic MybatisPlusInterceptor getMybatisPlusInterceptor() {MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); // 攔截器interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 分頁(yè)處理return interceptor;} }創(chuàng)建IDeptDAO數(shù)據(jù)接口
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接口開(kāi)發(fā)完成 }在生產(chǎn)端需要提供有業(yè)務(wù)接口的實(shí)現(xiàn)子類(lèi)
@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); // 設(shè)置模糊查詢(xún)操作int count = this.deptDAO.selectCount(wrapper); // 統(tǒng)計(jì)個(gè)數(shù)// 實(shí)現(xiàn)數(shù)據(jù)的查詢(xún)處理IPage<Dept> page = this.deptDAO.selectPage(new Page<>(currentPage, lineSize, count), wrapper);Map<String, Object> map = new HashMap<>(); // 包裝返回結(jié)果map.put("allDepts", page.getRecords()); //數(shù)據(jù)記錄map.put("allRecorders", page.getTotal()); //總數(shù)map.put("allPages", page.getPages()); //頁(yè)數(shù)return map;} }總結(jié)
以上是生活随笔為你收集整理的MyBatisPlus分页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 电脑更改了硬件或软件开不了机了怎么办?
- 下一篇: Ribbon 客户端负载均衡