为什么Jpa排序在Spring中不能与Pageable一起使用?

0pizxfdo  于 2022-11-23  发布在  Spring
关注(0)|答案(1)|浏览(134)

分页工作正常,但我无法根据特定字段对数据进行排序。我的存储库方法Page<AdvertSearch> findAll(Pageable pageable);
我的实体类是:

public class AdvertSearch {

    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name = "id", nullable = false, columnDefinition = "VARCHAR(36)")
    private String id;

    private String advertId;
    private String officeId;
    private String officeName;

    //TODO: type hangi Point olacak hangi class olacak karar verilecek
    @Column(nullable = false, columnDefinition = "POINT SRID 4326")
    private Point location;

    private OfficeType officeType;
    private String city;
    private String district;
    private String mainOfficeId;
    private Integer facilityCount;
    private Integer virtualPackageCount;
    private BuildingType buildingType;
    private Integer securityCount;
    private Double monthlyPrice;
    private String currency;
    private Integer capacity;

    //TODO: officelerde rating olmayacak diye konustuk bunun da netlestirilmesi gerek
    private Double rating;
    private Integer ratingCount;
}

我的 Postman 要求是:http://localhost:8080/advertsearch/findallbypage?page=0&size=4&sort=district&direction=desc

正如你所看到的,我想根据地区对数据进行排序,但是它不起作用。是我的请求错了吗?还是JPA中的Pageable

9rygscc1

9rygscc11#

方向应在排序参数中:
?page=0&size=4&sort=district,desc
您可以找到更多示例here

相关问题