I have a request like:
example.com/search?sort=myfield1,-myfield2,myfield3
I would like to split those params to bind a List<String>
sort in my controller or List<SortParam>
where SortParam
is the class with fields like: name
(String) and ask
(boolean).
So the final controller would look like this:
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<MyResponse> search(@RequestParam List<String> sort) {
//...
}
or
@RequestMapping(value = "/search", method = RequestMethod.GET)
public ResponseEntity<MyResponse> search(@RequestParam List<SortParam> sort) {
//...
}
Is there a way to make it?
UPDATE:
The standard way of passing parameters does not satisfy my requirements. I.e. I cannot use sort=myfield1&sort=-myfield2&sort=myfield3
. I have to use comma separated names.
Also, I do understand that I can accept @RequestParam String sort
in my controller and then split the string inside the controller like sort.split(",")
but it also doesn't solve the above problem.