几个重要部分:
<!--MYSQL-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.2.0</version>
</dependency>
<!-- mybatis 分页-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
appplication.properties
pagehelper.autoDialect=true
pagehelper.closeConn=true
@Override
public ServerResponse<PageInfo<MovieVo>> selectMovieList(String categoryId, String keyWord, Integer page, Integer pageSize) {
System.out.print(pageSize);
PageHelper.startPage(page, pageSize);
List<Movie> movies = movieMapper.selectMovieList(categoryId, keyWord);
ArrayList<MovieVo> movieVoList = newArrayList();
for (Movie movie: movies) {
movieVoList.add(convertToMovieVo(movie));
}
PageInfo<MovieVo> pageInfo = new PageInfo(movies);
pageInfo.setList(movieVoList);
return ServerResponse.createBySuccess(pageInfo);
}
{
"status":0,
"msg":null,
"data":{
"total":4,
"list":[
{
"id":29,
"categoryId":null,
"name":"Haier/海尔HJ100-1HU1 10公斤滚筒洗衣机全自动带烘干家用大容量 洗烘一体",
"subtitle":"门店机型 德邦送货",
"mainImage":null
},
{
"id":28,
"categoryId":null,
"name":"4+64G送手环/Huawei/华为 nova 手机P9/P10plus青春",
"subtitle":"NOVA青春版1999元",
"mainImage":null
}
],
"pageNum":1,
"pageSize":2,
"size":2,
"startRow":1,
"endRow":2,
"pages":2,
"prePage":0,
"nextPage":2,
"isFirstPage":true,
"isLastPage":false,
"hasPreviousPage":false,
"hasNextPage":true,
"navigatePages":8,
"navigatepageNums":[
1,
2
],
"navigateFirstPage":1,
"navigateLastPage":2
},
"success":true
}