Home > Mobile >  Send pageable object and search params to Spring Boot endpoint
Send pageable object and search params to Spring Boot endpoint

Time:09-17

I have this endpoint which I want to use to get data as pages:

 @RequestMapping(method = RequestMethod.GET, value = "/task", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> processTask(@Valid TaskSearchParams params, Pageable pageable)
    {
        .....    
        return new ResponseEntity<>(....., HttpStatus.OK);
    }

Search Prams DTO:

@Getter
@Setter
public class TaskSearchParams {

    private String title;
    private String status;
}

What payload for TaskSearchParams and Pageable I need to send? I tried:

{
    "size": 1,
    "pageNumber": 1,
    "offset": 1,
    "sort": "DESC"
}

But I'm not sure how I need to include TaskSearchParams.

CodePudding user response:

If these are path variables, you should enclose them in curly braces and annotate variable with @PathVariable

@RequestMapping(method = RequestMethod.GET, value = "/task/{title}/{status}", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> processTask(@Valid @PathVariable String title, @PathVariable String status, Pageable pageable)
    {
        .....    
        return new ResponseEntity<>(....., HttpStatus.OK);
    }
  • Related