Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

put 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    }}
Comment

PREVIOUS NEXT
Code Example
Java :: sort a list in java according to last name 
Java :: java try...catch 
Java :: Java TreeMap Example NavigableMap 
Java :: webview dark mode android 
Java :: new in t arrray java 
Java :: how to change background color of grid in grid layout in android 
Java :: java number reverse 
Java :: how to compare doubles in java 
Java :: 2048 java code 
Java :: convert integer arraylist to array java 
Java :: determine if a number is factorial in Java 
Java :: Java telegram bot dependency 
Java :: java add two arrays together 
Java :: java dictionary initialization 
Java :: convert string to boolean java 
Java :: java change hashmap value 
Java :: java boolean data type 
Java :: round to the next multiple of 5 
Java :: java log4j example 
Java :: different constructiors in java and what they do explained 
Java :: convert string array to string 
Java :: splash full screen android 
Java :: spring mvc 
Java :: method overloading 
Java :: nested class in java 8 
Java :: java eth 
Java :: Print Positives of array 
Java :: prefix vs postfix increment java 
Java :: map indexof java 
Java :: open cv for java 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =