SpringBoot项目使用Mybatis-plus插件分页

SpringBoot项目使用Mybatis-plus插件分页,第1张

SpringBoot项目使用Mybatis-plus插件分页

1. 在需要使用的模块的pom.xml中添加Mybatis-plus依赖

        
            com.baomidou
            mybatis-plus-boot-starter
            3.2.0
        

2. 配置Mybatis-plus的全局配置,不然Mybatis-plus的分页作用会失效

@Configuration
public class MybatisPlusConfig {
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor page = new PaginationInterceptor();
        page.setDialectType("mysql"); //设置数据库类型
        return page;
    }
}

3. 使用Mybatis-plus 分页查询

	QueryWrapper queryWrapper = new QueryWrapper();
	queryWrapper.eq("party_id",request.getPartyId());//添加查询条件,可以添加多个
	queryWrapper.orderByDesc("last_up_date");//添加排序条件,可以添加多个
	Integer totalNumber = commPartyMapper.selectCount(queryWrapper); //commPartyMapper 要继承com.baomidou.mybatisplus.core.mapper.baseMapper包下的baseMapper
	//Integer pageNum = body.getPageNum();
	//Integer pageSize = body.getPageSize();
	//pageNum = pageNum == null ? 1 : pageNum;
	//pageSize = pageSize == null ? 10 : pageSize;
	//IPage page = new Page<>(pageNum,pageSize);
	IPage page = new Page<>(1,10);
	IPage pageDo = commPartyMapper.selectPage(page, queryWrapper);
	List result = pageDo.getRecords();

4. commPartyMapper

public interface CommPartyMapper extends baseMapper {
}

5. CommPartyDO

@Data
@TableName("comm_party") //表名
public class CommPartyDO {
	private String partyId;
	private String partyName;
	private String partyType;
	......
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/zaji/5685578.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存