GetMapping( /rest/v1/books ) In Spring Rest Api

[Solved] GetMapping( /rest/v1/books ) In Spring Rest Api | Java Frameworks Spring - Code Explorer | yomemimo.com
Question : GetMapping("/rest/v1/books") in spring rest api

Answered by : blueeyed-bug-fdrxubjlrmm5

@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 }}

Source : https://www.dariawan.com/tutorials/rest/http-methods-spring-restful-services/ | Last Update : Wed, 24 Nov 21

Answers related to GetMapping( /rest/v1/books ) in spring rest api

Code Explorer Popular Question For Java Frameworks Spring