We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a04478b commit 4e74625Copy full SHA for 4e74625
src/main/java/com/jap/rest101/controller/UserController.java
@@ -7,6 +7,7 @@
7
import org.springframework.web.bind.annotation.*;
8
9
import java.util.List;
10
+import java.util.Optional;
11
12
@RestController
13
@RequestMapping("/users")
@@ -26,5 +27,13 @@ public ResponseEntity<List<User>> listUser() {
26
27
List<User> users = repository.findAll();
28
return ResponseEntity.ok(users);
29
}
30
+
31
+ @GetMapping("/{id}")
32
+ public ResponseEntity<?> getUser(@PathVariable("id") Long id) {
33
+ Optional<User> user = repository.findById(id);
34
+ if (user.isEmpty())
35
+ return ResponseEntity.notFound().build();
36
+ return ResponseEntity.ok(user);
37
+ }
38
39
0 commit comments