使用mybatis-plus实现分页查询
- pom.xml导入mybatis-plus插件
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
- 编写config 实现分页插件
@Configuration
@MapperScan("mapper")
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
- 编写controller(传入pageNo, pageSize)
IPage<T> iPage = tService.page(new Page<>(pageNo,pageSize));
iPage包括:
{
"records": [], list
"total": 0,总数
"size": 3,pageSize
"current": 1,pageNo
"searchCount": true,
"pages": 0 总页数
}
附:mapper,service结构(如需代码构造器Mybatis-Plus代码构造器)
//mapper
@Mapper
public interface Tmapper extends BaseMapper<T> {
}
//service
public interface TService extends IService<T> {
}
//serviceImpl
@Service
public class TServiceImpl extends ServiceImpl<Tmapper,T> implements TService {
}
PS:一起学习,如有错误!请多多指教!!!谢谢