Mybatis-plus实现分页查询




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("你的mapper存在的目录")
public class MybatisPlusConfig {
    
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
 public BaseResponse> recommendUsers(Long pageSize, Long pageNum, HttpServletRequest request) {
        // 创建一个查询包装器,用于后续的用户查询操作。
        QueryWrapper queryWrapper = new QueryWrapper<>();

        Page userList = userService.page(new Page<>(pageNum, pageSize), queryWrapper);


        // 构造一个成功响应,并将处理后的用户列表作为响应的数据返回。
        return ResultUtils.success(userList);
    }

你可能感兴趣的:(mybatis)