Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

POST method) in spring rest api

@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();    }}
Comment

PREVIOUS NEXT
Code Example
Java :: Java Exception handling using try...catch 
Java :: javax 
Java :: private method in interface java 
Java :: configure JWT on Springboot 
Java :: radix sort 
Java :: Java forEach() Method 
Java :: why string is immutable in java 
Java :: buy and sell stock 
Java :: java pass by reference 
Java :: abstract class java 
Java :: how to use a while statement with char in java 
Java :: java to python 
Java :: update a key in the firebase realtime database java 
Java :: how todo a timeout test java 
Java :: java cant use string functions after changing an integer into string 
Java :: Java Custom Annotations 
Java :: intergers are appearing as string in Json 
Java :: English print format number in java 
Java :: list in list 
Java :: Android number format thousands separator 
Java :: polymorphism array with abstract class java 
Java :: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; 
Java :: SmallChange 
Java :: java find index of first alpha character in string 
Java :: jtable fill panel 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: print jtable in java 
Java :: getBatteryPercentage android studio 
Java :: copy array of objects in java 
Java :: reader java 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =