wuruize888 2018-06-03 00:22 采纳率: 66.7%
浏览 1208
已采纳

关于jpa分页查询的问题,谢谢解答

 @Override
    public Page<Auth> getAllAuth(Integer pageNum, Integer pageSize) {

        Sort sort = new Sort(Sort.Direction.ASC, "sort");
        Pageable pageable = PageRequest.of(pageNum, pageSize, sort);
        Specification<Auth> authSpecification = new Specification<Auth>() {
            @Override
            public Predicate toPredicate(Root<Auth> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
                query.select(root.get("authID").get("authName").get("parentDataBase").get("onSqlTableName").get("authAddress").get("remark").get("authClassType"));/

                                /我想限制输出字段,如果不加这条是全部输出。加了这条报错 Illegal attempt to dereference path source [null.authID] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.authID] of basic type
//另外如果我想在最终输出上增加一个自定义字段,有没有官方的方法可以用?谢谢各位帮忙
                                query.groupBy(root.get("parentAddr"));
                query.where(cb.equal(root.get("authClassType").as(String.class), "1"));
                query.orderBy(cb.desc(root.get("sort").as(Integer.class)));
                return query.getGroupRestriction();
            }
        };

        Page<Auth> page = authRepository.findAll(authSpecification, pageable);
        System.err.println(page);
        return page;

    }
  • 写回答

3条回答 默认 最新

  • 生如夏花帅 2018-06-05 03:58
    关注
    List<PostMessage> postMessageList = postMessagePage.getContent();
        postMessageList.forEach(postMessage -> dtoList.add(transPostToDto(postMessage)));
    
                  private PostMessageDto transPostToDto(PostMessage postMessage){
        PostMessageDto dto = new PostMessageDto();
        BeanUtils.copyProperties(postMessage, dto,"content");
    
        return dto;
    }
        这是我写的类似的
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 已采纳回答 10月21日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog