📜  放入 spring rest api - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:37.833000             🧑  作者: Mango

代码示例1
@GetMapping("/rest/v1/books")public ResponseEntity> findAllBooks() {    List books = bookService.findAll();    return ResponseEntity.ok(books);  // return 200, with json body} @GetMapping("/rest/v1/books/{bookId}")public ResponseEntity 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    }}