Metoda post) w wiosennym interfejsie API REST
@PostMapping("/rest/v1/books")public ResponseEntity<Book> addBook(@RequestBody Book book) throws URISyntaxException { try { Book newBook = bookService.save(book); return ResponseEntity.created(new URI("/rest/v1/books/" + newBook.getId())) .body(book); } catch (ResourceAlreadyExistsException ex) { // log exception first, then return Conflict (409) logger.error(ex.getMessage()); return ResponseEntity.status(HttpStatus.CONFLICT).build(); } catch (BadResourceException ex) { // log exception first, then return Bad Request (400) logger.error(ex.getMessage()); return ResponseEntity.status(HttpStatus.BAD_REQUEST).build(); }}
Blue-eyed Bug