Skip to content

Commit 4e74625

Browse files
committed
init get detail data
1 parent a04478b commit 4e74625

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/main/java/com/jap/rest101/controller/UserController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.web.bind.annotation.*;
88

99
import java.util.List;
10+
import java.util.Optional;
1011

1112
@RestController
1213
@RequestMapping("/users")
@@ -26,5 +27,13 @@ public ResponseEntity<List<User>> listUser() {
2627
List<User> users = repository.findAll();
2728
return ResponseEntity.ok(users);
2829
}
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+
}
2938
}
3039

0 commit comments

Comments
 (0)