Search in sources :

Example 76 with IPage

use of com.baomidou.mybatisplus.core.metadata.IPage in project tutorials-java by Artister.

the class PaginationTest method tests1.

@Test
public void tests1() {
    System.out.println("----- baseMapper 自带分页 ------");
    Page<User> page = new Page<>(1, 5);
    IPage<User> userIPage = mapper.selectPage(page, new QueryWrapper<User>().eq("age", 20).eq("name", "Jack"));
    assertThat(page).isSameAs(userIPage);
    System.out.println("总条数 ------> " + userIPage.getTotal());
    System.out.println("当前页数 ------> " + userIPage.getCurrent());
    System.out.println("当前每页显示数 ------> " + userIPage.getSize());
    print(userIPage.getRecords());
    System.out.println("----- baseMapper 自带分页 ------");
    System.out.println("json 正反序列化 begin");
    String json = JSON.toJSONString(page);
    Page<User> page1 = JSON.parseObject(json, TypeBuilder.newInstance(Page.class).addTypeParam(User.class).build());
    print(page1.getRecords());
    System.out.println("json 正反序列化 end");
    System.out.println("----- 自定义 XML 分页 ------");
    MyPage<User> myPage = new MyPage<User>(1, 5).setSelectInt(20).setSelectStr("Jack");
    ParamSome paramSome = new ParamSome(20, "Jack");
    MyPage<User> userMyPage = mapper.mySelectPage(myPage, paramSome);
    assertThat(myPage).isSameAs(userMyPage);
    System.out.println("总条数 ------> " + userMyPage.getTotal());
    System.out.println("当前页数 ------> " + userMyPage.getCurrent());
    System.out.println("当前每页显示数 ------> " + userMyPage.getSize());
    print(userMyPage.getRecords());
    System.out.println("----- 自定义 XML 分页 ------");
}
Also used : User(com.baomidou.mybatisplus.samples.pagination.entity.User) ParamSome(com.baomidou.mybatisplus.samples.pagination.model.ParamSome) MyPage(com.baomidou.mybatisplus.samples.pagination.model.MyPage) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) MyPage(com.baomidou.mybatisplus.samples.pagination.model.MyPage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 77 with IPage

use of com.baomidou.mybatisplus.core.metadata.IPage in project tutorials-java by Artister.

the class DeluxeTest method testPage.

@Test
public void testPage() {
    System.out.println("------ 自定义 xml 分页 ------");
    UserPage selectPage = new UserPage(1, 5).setSelectInt(20);
    UserPage userPage = mapper.selectUserPage(selectPage);
    Assert.assertSame(userPage, selectPage);
    System.out.println("总条数 ------> " + userPage.getTotal());
    System.out.println("当前页数 ------> " + userPage.getCurrent());
    System.out.println("当前每页显示数 ------> " + userPage.getSize());
    print(userPage.getRecords());
    System.out.println("------ baseMapper 自带分页 ------");
    Page<User> page = new Page<>(1, 5);
    IPage<User> userIPage = mapper.selectPage(page, new QueryWrapper<User>().eq("age", 20));
    Assert.assertSame(userIPage, page);
    System.out.println("总条数 ------> " + userIPage.getTotal());
    System.out.println("当前页数 ------> " + userIPage.getCurrent());
    System.out.println("当前每页显示数 ------> " + userIPage.getSize());
    print(userIPage.getRecords());
}
Also used : User(com.baomidou.mybatisplus.samples.deluxe.entity.User) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) UserPage(com.baomidou.mybatisplus.samples.deluxe.model.UserPage) IPage(com.baomidou.mybatisplus.core.metadata.IPage) UserPage(com.baomidou.mybatisplus.samples.deluxe.model.UserPage) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 78 with IPage

use of com.baomidou.mybatisplus.core.metadata.IPage in project lamp-util by zuihou.

the class EchoServiceImpl method parse.

/**
 * 1,遍历字段,解析出那些字段上标记了@Echo注解
 *
 * @param obj          对象
 * @param typeMap      数据
 * @param depth        当前递归深度
 * @param ignoreFields 忽略回显的字段
 */
private void parse(Object obj, Map<LoadKey, Map<Serializable, Object>> typeMap, int depth, String... ignoreFields) {
    if (obj == null) {
        return;
    }
    if (depth > ips.getMaxDepth()) {
        log.info("递归回显层级过深 或 出现循环递归,最多执行 {} 次, 已执行 {} 次,已为您跳出循环", ips.getMaxDepth(), depth);
        return;
    }
    if (obj instanceof IPage) {
        List<?> records = ((IPage<?>) obj).getRecords();
        parseList(records, typeMap, depth, ignoreFields);
        return;
    }
    if (obj instanceof Collection) {
        parseList((Collection<?>) obj, typeMap, depth, ignoreFields);
        return;
    }
    // 解析方法上的注解,计算出obj对象中所有需要查询的数据
    List<Field> fields = ClassManager.getFields(obj.getClass());
    for (Field field : fields) {
        FieldParam fieldParam = getFieldParam(obj, field, typeMap, innerTypeMap -> parse(ReflectUtil.getFieldValue(obj, field), innerTypeMap, depth + 1, ignoreFields), ignoreFields);
        if (fieldParam == null) {
            continue;
        }
        LoadKey type = fieldParam.getLoadKey();
        Map<Serializable, Object> valueMap = typeMap.getOrDefault(type, new ConcurrentHashMap<>(DEF_MAP_SIZE));
        valueMap.put(fieldParam.getActualValue(), Collections.emptyMap());
        typeMap.put(type, valueMap);
    }
}
Also used : LoadKey(top.tangyh.basic.echo.manager.LoadKey) Field(java.lang.reflect.Field) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Serializable(java.io.Serializable) FieldParam(top.tangyh.basic.echo.manager.FieldParam) Collection(java.util.Collection)

Example 79 with IPage

use of com.baomidou.mybatisplus.core.metadata.IPage in project mogu_blog_v2 by moxi624.

the class CommentServiceImpl method getPageList.

@Override
public IPage<Comment> getPageList(CommentVO commentVO) {
    QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(commentVO.getKeyword()) && !StringUtils.isEmpty(commentVO.getKeyword().trim())) {
        queryWrapper.like(SQLConf.CONTENT, commentVO.getKeyword().trim());
    }
    if (commentVO.getType() != null) {
        queryWrapper.eq(SQLConf.TYPE, commentVO.getType());
    }
    if (StringUtils.isNotEmpty(commentVO.getSource()) && !SysConf.ALL.equals(commentVO.getSource())) {
        queryWrapper.eq(SQLConf.SOURCE, commentVO.getSource());
    }
    if (StringUtils.isNotEmpty(commentVO.getUserName())) {
        String userName = commentVO.getUserName();
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.like(SQLConf.NICK_NAME, userName);
        userQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
        List<User> list = userService.list(userQueryWrapper);
        if (list.size() > 0) {
            List<String> userUid = new ArrayList<>();
            list.forEach(item -> {
                userUid.add(item.getUid());
            });
            queryWrapper.in(SQLConf.USER_UID, userUid);
        } else {
            // 当没有查询到用户时,默认UID
            queryWrapper.in(SQLConf.USER_UID, SysConf.DEFAULT_UID);
        }
    }
    Page<Comment> page = new Page<>();
    page.setCurrent(commentVO.getCurrentPage());
    page.setSize(commentVO.getPageSize());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    queryWrapper.orderByDesc(SQLConf.CREATE_TIME);
    IPage<Comment> pageList = commentService.page(page, queryWrapper);
    List<Comment> commentList = pageList.getRecords();
    Set<String> userUidSet = new HashSet<>();
    Set<String> blogUidSet = new HashSet<>();
    commentList.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            userUidSet.add(item.getUserUid());
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            userUidSet.add(item.getToUserUid());
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            blogUidSet.add(item.getBlogUid());
        }
    });
    // 获取博客
    Collection<Blog> blogList = new ArrayList<>();
    if (blogUidSet.size() > 0) {
        blogList = blogService.listByIds(blogUidSet);
    }
    Map<String, Blog> blogMap = new HashMap<>();
    blogList.forEach(item -> {
        // 评论管理并不需要查看博客内容,因此将其排除
        item.setContent("");
        blogMap.put(item.getUid(), item);
    });
    // 获取头像
    Collection<User> userCollection = new ArrayList<>();
    if (userUidSet.size() > 0) {
        userCollection = userService.listByIds(userUidSet);
    }
    final StringBuffer fileUids = new StringBuffer();
    userCollection.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            fileUids.append(item.getAvatar() + SysConf.FILE_SEGMENTATION);
        }
    });
    String pictureList = null;
    if (fileUids != null) {
        pictureList = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    Map<String, String> pictureMap = new HashMap<>();
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    Map<String, User> userMap = new HashMap<>();
    userCollection.forEach(item -> {
        // 判断头像是否为空
        if (pictureMap.get(item.getAvatar()) != null) {
            item.setPhotoUrl(pictureMap.get(item.getAvatar()));
        }
        userMap.put(item.getUid(), item);
    });
    for (Comment item : commentList) {
        try {
            ECommentSource commentSource = ECommentSource.valueOf(item.getSource());
            item.setSourceName(commentSource.getName());
        } catch (Exception e) {
            log.error("ECommentSource 转换异常");
        }
        if (StringUtils.isNotEmpty(item.getUserUid())) {
            item.setUser(userMap.get(item.getUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getToUserUid())) {
            item.setToUser(userMap.get(item.getToUserUid()));
        }
        if (StringUtils.isNotEmpty(item.getBlogUid())) {
            item.setBlog(blogMap.get(item.getBlogUid()));
        }
    }
    pageList.setRecords(commentList);
    return pageList;
}
Also used : User(com.moxi.mogublog.commons.entity.User) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) ECommentSource(com.moxi.mougblog.base.enums.ECommentSource) Blog(com.moxi.mogublog.commons.entity.Blog) Comment(com.moxi.mogublog.commons.entity.Comment) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DeleteException(com.moxi.mougblog.base.exception.exceptionType.DeleteException)

Example 80 with IPage

use of com.baomidou.mybatisplus.core.metadata.IPage in project mogu_blog_v2 by moxi624.

the class LinkServiceImpl method getPageList.

@Override
public IPage<Link> getPageList(LinkVO linkVO) {
    QueryWrapper<Link> queryWrapper = new QueryWrapper<>();
    if (StringUtils.isNotEmpty(linkVO.getKeyword()) && !StringUtils.isEmpty(linkVO.getKeyword().trim())) {
        queryWrapper.like(SQLConf.TITLE, linkVO.getKeyword().trim());
    }
    if (linkVO.getLinkStatus() != null) {
        queryWrapper.eq(SQLConf.LINK_STATUS, linkVO.getLinkStatus());
    }
    if (StringUtils.isNotEmpty(linkVO.getOrderByAscColumn())) {
        String column = StringUtils.underLine(new StringBuffer(linkVO.getOrderByAscColumn())).toString();
        queryWrapper.orderByAsc(column);
    } else if (StringUtils.isNotEmpty(linkVO.getOrderByDescColumn())) {
        String column = StringUtils.underLine(new StringBuffer(linkVO.getOrderByDescColumn())).toString();
        queryWrapper.orderByDesc(column);
    } else {
        queryWrapper.orderByDesc(SQLConf.SORT);
    }
    Page<Link> page = new Page<>();
    page.setCurrent(linkVO.getCurrentPage());
    page.setSize(linkVO.getPageSize());
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    IPage<Link> pageList = linkService.page(page, queryWrapper);
    List<Link> linkList = pageList.getRecords();
    final StringBuffer fileUids = new StringBuffer();
    // 给友情链接添加图片
    linkList.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            fileUids.append(item.getFileUid() + SysConf.FILE_SEGMENTATION);
        }
    });
    String pictureList = null;
    Map<String, String> pictureMap = new HashMap<>();
    if (fileUids != null) {
        pictureList = pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureList);
    picList.forEach(item -> {
        pictureMap.put(item.get(SysConf.UID).toString(), item.get(SysConf.URL).toString());
    });
    for (Link item : linkList) {
        // 获取图片
        if (StringUtils.isNotEmpty(item.getFileUid())) {
            List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getFileUid(), Constants.SYMBOL_COMMA);
            List<String> pictureListTemp = new ArrayList<>();
            pictureUidsTemp.forEach(picture -> {
                pictureListTemp.add(pictureMap.get(picture));
            });
            item.setPhotoList(pictureListTemp);
        }
    }
    pageList.setRecords(linkList);
    return pageList;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) Link(com.moxi.mogublog.commons.entity.Link)

Aggregations

IPage (com.baomidou.mybatisplus.core.metadata.IPage)197 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)152 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)73 ApiOperation (io.swagger.annotations.ApiOperation)28 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)20 PageDTO (com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO)19 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 LoginUser (org.jeecg.common.system.vo.LoginUser)16 JSONObject (com.alibaba.fastjson.JSONObject)15 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 PageInfo (org.apache.dolphinscheduler.api.utils.PageInfo)13 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)11 Result (org.jeecg.common.api.vo.Result)10 List (java.util.List)9 User (org.apache.dolphinscheduler.dao.entity.User)9 Field (java.lang.reflect.Field)8 Date (java.util.Date)8 Collectors (java.util.stream.Collectors)7 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)7