baomidou.mybatisplus分页插件使用

1、jar包引用
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.1.0</version>
</dependency>

2、java插件配置
@Configuration
public class MybatisConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}

3、service实现使用
public List<UserMessageDTO> getListPage(Long userId, Long pageNum, Long pageSize) {

if (ObjectUtils.isEmpty(userId)) {
throw new CommonException("无用户信息,获取用户消息数据失败");
}
pageNum = pageNum != null ? pageNum : CommonEnum.PageInfoEnum.PAGE_NUM.getValue();
pageSize = pageSize != null ? pageSize : CommonEnum.PageInfoEnum.PAGE_SIZE.getValue();

Page<UserMessageDO> page = new Page<>();
List<UserMessageDO> list = userMessageMapper.getListPage(page, userId);
page.setRecords(list);

return null;
}

4、mapper使用
public interface UserMessageMapper {

int insert(UserMessageDO userMessageDO);

List<UserMessageDO> getListPage(Page<UserMessageDO> page, Long userId);
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容