Controller vs RestController
[@Controller 예제 코드]
@Controller
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@GetMapping(value = "/users")
public @ResponseBody ResponseEntity<User> findUser(@RequestParam("userName") String userName){
return ResponseEntity.ok(userService.findUser(user));
}
}
[@RestController]
@RestController는 @Controller에 @ResponseBody가 추가!
(Json 형태로 객체 데이터를 반환하는 것)
[@RestController 예제 코드]
@RestController
@RequiredArgsConstructor
public class UserController {
private final UserService userService;
@GetMapping(value = "/users")
public ResponseEntity<User> findUserWithResponseEntity(@RequestParam("userName") String userName){
return ResponseEntity.ok(userService.findUser(user));
}
}