Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RestController
- @RequestMapping (value = "/test")
- public class TestController {
- private final UserService userService;
- public TestController(UserService userService) {
- this.userService = userService;
- }
- // Получить пользователя по его уникальному идентификатору (простой)
- // localhost:8080/test/users/get/id (любое целое число)
- @RequestMapping(value = "/users/get/{id}", method = RequestMethod.GET)
- public String fetchUser(@PathVariable Long id) {
- return userService.fetchUser(id);
- }
- // Получить пользователя по его уникальному идентификатору (с обработкой исключений)
- // localhost:8080/test/users/get/id (любое целое число)
- @RequestMapping(value = "/users/get/{id}", method = RequestMethod.GET)
- public String getSimpleGreeting(@PathVariable Long id) {
- try {
- return ResponseEntity.status(HttpStatus.OK).body(userService.fetchUser(id));
- } catch (UserNotFoundException exception) {
- return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(HttpStatus.BAD_REQUEST.getReasonPhrase());
- }
- }
- }
Add Comment
Please, Sign In to add comment