I need a rest get method that search books by multiple optional parameters. This is the method:
@GetMapping("/all")
public ResponseEntity<Optional<List<Book>>> findByAll(@RequestParam(value = "title") String title,
@RequestParam(value = "author") String author, @RequestParam(value = "new", required = false) boolean new,
@RequestParam(value = "category", required = false) int category) {
Optional<List<Book>> bookList = booksService.findByAll(title, author, new, category);
return new ResponseEntity<Optional<List<Book>>>(bookList, HttpStatus.OK);
}
all of theese parameters should be optional. For example, if all input are empty should return all the books from db. required=false needs a defaultvalue but i cannot set a default value for new and category.