简体   繁体   English

Spring 引导查询 Dsl java.lang.UnsupportedOperationException

[英]Spring Boot QueryDsl java.lang.UnsupportedOperationException

    //Page<Board> result = (Page<Board>) repo.findAll();
    Page<Board> result = repo.findAll(builder, pageable);
    System.out.println("넘어오긴했음");
    System.out.println("PAGE SIZE : "+result.getSize());
    System.out.println("TOTAL PAGES : " + result.getTotalPages());
    System.out.println("TOTAL COUNT : "+ result.getTotalElements());
    System.out.println("NEXT : "+result.nextPageable());
    
    //List<Board> list =new ArrayList<Board>(result.getContent());

    //list.forEach(b -> System.out.println(b));

it returns java.lang.UnsupportedOperationException它返回 java.lang.UnsupportedOperationException

how can i get Page by use findall method?如何使用 findall 方法获取 Page?

most said edit here最常说的编辑在这里

List<Board> list = result.getContent();

to

List<Board> list =new ArrayList<Board>(result.getContent());   

but my problem is occured但我的问题发生了

Page<Board> result = repo.findAll(builder, pageable);

here is trace这是痕迹

java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
at com.querydsl.jpa.JPQLSerializer.visitConstant(JPQLSerializer.java:327)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:221)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:36)
at com.querydsl.core.types.ConstantImpl.accept(ConstantImpl.java:140)
at 
com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:122)
at com.querydsl.core.support.SerializerBase.visitOperation(SerializerBase.java:301)
at com.querydsl.jpa.JPQLSerializer.visitOperation(JPQLSerializer.java:422)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:262)
at com.querydsl.core.support.SerializerBase.visit(SerializerBase.java:36)
at com.querydsl.core.types.OperationImpl.accept(OperationImpl.java:83)
at com.querydsl.core.support.SerializerBase.handle(SerializerBase.java:122)
at com.querydsl.core.support.SerializerBase.visitOperation(SerializerBase.java:298)

I think findAll can accept a Pageable parameter,我认为findAll可以接受Pageable参数,

Page<Board> findAll(Pageable pageable);

This is not related to QueryDSL .这与QueryDSL

Check my samples of Spring Data JPA/QueryDSL (You should update to the latest Spring yourself).检查我的 Spring 数据 JPA/QueryDSL 样本(您应该自己更新到最新的 Spring)。

In PagingAndSortingRepository findAll method allow only Pageable parameter在 PagingAndSortingRepository 中的findAll方法只允许Pageable参数

public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
  Iterable<T> findAll(Sort var1);

  Page<T> findAll(Pageable var1);
}

so if you want findAll method return Page through querydsl with builder因此,如果您希望 findAll 方法通过带有构建器的querydsl返回Page
then extend CustomRepository like this custom-implementation-of-intermediate-repository-in-spring-data然后扩展 CustomRepository 像这样custom-implementation-of-intermediate-repository-in-spring-data

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM