Paging is working good but I cannot sort the data according to a specific field.
My repository method Page<AdvertSearch> findAll(Pageable pageable);
My entity class is:
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;
}
My postman request is: http://localhost:8080/advertsearch/findallbypage?page=0&size=4&sort=district&direction=desc
As you see I want to sort the data according to district but it is not working. Is my request wrong ? Or is it about Pageable
in JPA ?
CodePudding user response:
The direction should be in the sort param :
?page=0&size=4&sort=district,desc
You can find more examples here