흔히(?) 등장하는 `@ResponseBody`의 사용 예이다.
1.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ResponseBodyExampleController1 { | |
@GetMapping("/") | |
public @ResponseBody String someMethod() { | |
return "result"; | |
} | |
} |
2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ResponseBodyExampleController2 { | |
@GetMapping("/") | |
public | |
@ResponseBody | |
String someMethod() { | |
return "result"; | |
} | |
} |
그래서 매번 다시 1. 처럼 일일이 손으로 수정하곤 했었는데,
다음과 같은 사실을 깨달았다.
`@ResponseBody`는 `ElementType.METHOD`를 대상으로(@Target)하고 있어서 메서드 아무데나 갖다놔도 된다는 것을.
3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
public class ResponseBodyExampleController3 { | |
@ResponseBody | |
@GetMapping("/") | |
public String someMethod() { | |
return "result"; | |
} | |
} |
기쁘다 흑흑.
이제 더이상 삽질은 없다!