springboot+mybatis-plus分页查询

1.先依赖好mybatis-plus



   com.baomidou
   mybatis-plus-boot-starter
   3.1.1

2.配置

/**
 * @description:mybatis-plus配置
 * @author: Administrator
 * @date: 2019-04-27 13:42
 */
@Configuration
public class MybatisPlusConfig {
    /**
     * 性能分析拦截器,不建议生产使用 用来观察 SQL 执行情况及执行时长, 默认dev,staging 环境开启
     * @author fxbin
     * @return com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
     */
    @Bean
    @Profile({"dev", "staging"})
    public PerformanceInterceptor performanceInterceptor(){

        //启用性能分析插件, SQL是否格式化 默认false,此处开启
        return new PerformanceInterceptor().setFormat(true);
    }
    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}

3.mapper类

public interface ZhangKuanMapper extends BaseMapper {

    //分页查询
    IPage selectPageVo(Page page);
}

4.service类:

public interface ZhanKuanService extends IService {
   
}

5.impl类:

@Service
@Transactional //事务
public class ZhanKuanServiceImpl extends ServiceImpl implements ZhanKuanService{
    @Autowired
    private ZhangKuanMapper zhangKuanMapper;

    public IPage selectZhangKuanPage(Page page) {
        return zhangKuanMapper.selectPageVo(page);
    }

}

6.controller类:
 

@GetMapping("/all")
public AppResult> all(int page, int pageSize){
    log.info("分页查询=page="+page+"==数量=="+pageSize);

    Page mypage=new Page<>(page,pageSize);
    log.info("Page=="+JSON.toJSONString(mypage));

    IPage iPage=zhanKuanService.selectZhangKuanPage(mypage);
    log.info("分页查询=="+ JSON.toJSONString(iPage));

    return AppResultBuilder.success(iPage,ResultCode.SUCCESS);

}

7.结果:

 

你可能感兴趣的:(spring,boot,mybatis)