pom.xml添加依赖
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0-alpha</version>
</dependency>
模块目录结构 (DiseaseMapper 、 DiseaseMapper.xml在其他包中)
MybatisPlusConfig
package com.xxx.xxx.disease.controllers;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author ya
* @date 2018/7/19 20:27
*/
@Configuration
@MapperScan("com.xxx.xxx")
public class MybatisPlusConfig {
/**
* mybatis-plus分页插件<br>
* 文档:http://mp.baomidou.com<br>
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
return paginationInterceptor;
}
}
DiseasseController
/**
* 查询疾病信息,若无对属性值进行筛选则显示所有疾病信息
* @param currentPage 当前页面
* @param disease 疾病实体类,根据有传值的属性进行筛选
* @return
*/
@RequestMapping("selectByPage")
public ApiResult showByPage(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
Disease disease){
Page<Disease> page = new Page<Disease>(currentPage,pageSize);
QueryWrapper<Disease> diseaseQueryWrapperw = new QueryWrapper<Disease>(disease);
IPage<Disease> page1 = diseaseMapper.selectPage(page, diseaseQueryWrapperw);
return ApiResult.valueOf(page1); //ApiResult是对json格式的统一
}
参考:
https://blog.csdn.net/apicescn/article/details/79554597
https://www.oschina.net/news/97626/mybatis-plus-3-0-alpha-released