Spring Boot Starter Web - Pagination & Sorting

305 Views Asked by At

I have created a project using spring-boot-starter-web.

Additionally I have created a RESt controller like this:

@RestController
public class DaaController {

  @RequestMapping("/api/v1/data")
  public List<Data> getData(@RequestParam(value = "offset", defaultValue = "0") long offset,
                            @RequestParam(value = "limit", defaultValue = "-1") long limit,
                            @RequestParam(value = "sort", defaultValue = "") String sort) {
    [...]
  }
}

As you can see there are parameters for sorting and pagination.

As I want to be able to sort by multiple properties, the sorting could become quite annoying to implement, as I will have to provide a handling for analysing the provided sorting string (e.g. -manufactorer,+model).


Question:
Does Spring provide a better way of handling sorting and pagination parameters, or is the only way a custom implementation?


Note:
The data is not coming from a database, it is calculated data, so using the repository approach is not possible.

0

There are 0 best solutions below