mybatis-plus分页插件配置
package com.itxl.zhxy.utils;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
//@MapperScan("com.itxl.zhxy.mapper") //可以将主类中的注解移到此处
public class MybatisPlusConfig {
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new
PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
使用如下
Pagepage = new Page<>(pageId, 2);//pageId代表第几页,2代表一页2个数据 QueryWrapper wrapper = new QueryWrapper (); if (!"all".equals(con)){ //wrapper构造条件 wrapper.like("name",con).or().like("gender",con).or().like("address",con); } Page adminPage = adminMapper.selectPage(page, wrapper);//selectPage执行查询得到分页数据 return adminPage;
依赖如下:
com.baomidou mybatis-plus-boot-starter 3.5.1



