File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
spring-boot-example/src/main/java/de/rieckpil/blog/library Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ package de .rieckpil .blog .library ;
2+
3+ import java .awt .print .Book ;
4+
5+ import org .springframework .beans .factory .annotation .Autowired ;
6+ import org .springframework .http .ResponseEntity ;
7+ import org .springframework .web .bind .annotation .GetMapping ;
8+ import org .springframework .web .bind .annotation .PathVariable ;
9+ import org .springframework .web .bind .annotation .RequestMapping ;
10+ import org .springframework .web .bind .annotation .RestController ;
11+
12+ @ RestController
13+ @ RequestMapping ("/books" )
14+ public class BookController {
15+ private final BookService bookService ;
16+
17+ @ Autowired
18+ public BookController (BookService bookService ) {
19+ this .bookService = bookService ;
20+ }
21+
22+ @ GetMapping ("/{id}" )
23+ public ResponseEntity <Book > getBookById (@ PathVariable Long id ) {
24+ Book book = bookService .findById (id );
25+ if (book != null ) {
26+ return ResponseEntity .ok (book );
27+ } else {
28+ return ResponseEntity .notFound ().build ();
29+ }
30+ }
31+ }
Original file line number Diff line number Diff line change 1+ package de .rieckpil .blog .library ;
2+
3+ import java .awt .print .Book ;
4+
5+ import org .springframework .stereotype .Service ;
6+
7+ @ Service
8+ public class BookService {
9+ Book findById (Long id ) {
10+ return null ;
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments