mybatis-plus使用IPage分页返回vo对象

代码如下:但是无法返回 IPage(AppBookTypeVo)

// IPage<AppBookType> <里面需要写entity>,但是项目需求为 需要返回 AppBookTypeVo对象
@Override
public IPage<AppBookType> getPage(PageParam<AppBookTypeQuery> pageParam) {
    
    
    Page<AppBookType> platformPage = new Page<>(pageParam.getCurrent(), pageParam.getPageSize());
    QueryWrapper<AppBookType> qw = new QueryWrapper<>();
    AppBookTypeQuery appBookTypeQuery = pageParam.getCondition();
    if (null != appBookTypeQuery) {
    
    
        if (null != appBookTypeQuery.getId()) {
    
    
            qw.eq("id", appBookTypeQuery.getId());
        }
        if (!StringUtils.isEmpty(appBookTypeQuery.getTypeName())) {
    
    
            qw.like("type_name", appBookTypeQuery.getTypeName());
        }
        if (null != appBookTypeQuery.getEnable()) {
    
    
            qw.eq("enable", appBookTypeQuery.getEnable());
        }
    }
    qw.orderByAsc("type_order");
    return this.page(platformPage, qw);
}

解决方案:对查询到的page数据做一次convert()转换即可

@Override
public IPage<AppBookPassageChapterVo> chapterList(PageParam<AppBookPassageChapter> pageParam) {
    
    
    Page<AppBookPassage> platformPage = new Page<>(pageParam.getCurrent(), pageParam.getPageSize());
    QueryWrapper<AppBookPassage> qw = new QueryWrapper<>();
    qw.select(" DISTINCT book_code, book_chapter ");
    AppBookPassageChapter appBookPassageChapter = pageParam.getCondition();
    if (null != appBookPassageChapter) {
    
    
        if (!StringUtils.isEmpty(appBookPassageChapter.getBookCode())) {
    
    
            qw.eq("book_code", appBookPassageChapter.getBookCode());
        }
    }
    qw.orderByAsc("id");
    IPage<AppBookPassage> passageIPage = this.page(platformPage, qw);
    // 这里做一层转换即可
    return passageIPage.convert(AppBookPassage -> PojoConvertUtil.convertPojo(AppBookPassage, AppBookPassageChapterVo.class));
}

猜你喜欢

转载自blog.csdn.net/qq_17522211/article/details/129952215
今日推荐