Answers for "GetMapping("/rest/v1/books") in spring rest api"

0

GetMapping("/rest/v1/books") in spring rest api

@GetMapping("/rest/v1/books")public ResponseEntity<List<Book>> findAllBooks() {    List<Book> books = bookService.findAll();    return ResponseEntity.ok(books);  // return 200, with json body} @GetMapping("/rest/v1/books/{bookId}")public ResponseEntity<Book> findBookById(@PathVariable long bookId) {    try {        Book book = bookService.findById(bookId);        return ResponseEntity.ok(book);  // return 200, with json body    } catch (ResourceNotFoundException ex) {        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); // return 404, with null body    }}
Posted by: Guest on November-17-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language