pom.xml文件配置
<!--mybatisplus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.0.0</version>
</dependency>
<!--jdbc 存储-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--mysql 驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.42</version>
</dependency>
分页配置
@Configuration
public class MyBatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
return paginationInterceptor;
}
}
entity实体类
@Data
@TableName("T_BOOK")
public class Book {
/*图书编号*/
private String bookId;
/*书名*/
private String bookName;
/*作者*/
private String writer;
/*类别ID*/
private String sortId;
/*单价*/
private String price;
/*出版社*/
private String pubCompany;
/*出版日期*/
private String pubDate;
/*总数量*/
private String totalNum;
/*当前数量*/
private String currentNum;
/*入库日期*/
private String buyDate;
/*内容摘要*/
private String brief;
@TableField(exist = false)
private Sort sort;
}
进行分页查询,其中分页查询有两个区别在于一个显示实体类数据一个显示实体表数据
@GetMapping("/page")
public IPage<Book> selectBookPage(){
Page<Book> page = new Page<>(1, 2);
QueryWrapper<Book> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("Book_id");
IPage<Book> bookIPage = bookDao.selectPage(page, wrapper);
bookIPage.orders();
return bookIPage;
}
@GetMapping("/page1")
public IPage<Map<String, Object>> selectBookPage1(){
Page<Book> page = new Page<>(1, 2);
QueryWrapper<Book> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("Book_id");
IPage<Map<String, Object>> mapIPage = bookDao.selectMapsPage(page, wrapper);
return mapIPage;
}
查询效果图