Skip to content

Instantly share code, notes, and snippets.

@djkeh
Created September 8, 2017 09:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djkeh/6d5c7f4cb07b20b4f9485bec60fcdb32 to your computer and use it in GitHub Desktop.
Save djkeh/6d5c7f4cb07b20b4f9485bec60fcdb32 to your computer and use it in GitHub Desktop.
@RequestMapping 상속 문제 정리
package my.controllertest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* 이 문제의 수동 테스트 결과는 "/path/home" 이다.<br>
* 1. 자식클래스의 "path"가 부모 클래스나 인터페이스를 override했기 때문.<br>
* 2. 자식클래스 "path"를 제거할 경우 답은 "/if/home" 이다.<br>
* 3. 자식 인터페이스 "if"를 제거할 경우 답은 "/superif/home"<br>
* 4. 부모 인터페이스 "superif"를 제거할 경우 답은 "/if/home"<br>
* 5. 인터페이스 매핑 전부를 지웠을 경우 답은 "/super/home"<br>
* <br>
* 따라서, @RequestMapping 상속 적용 우선순위는 1. 자기 자신 클래스 2. 최종 인터페이스 3. 부모 인터페이스 4. 상속 클래스 이며,<br>
* 최고 우선순위 매핑이 나머지 매핑 정보를 덮어쓴다.
*
* @author Uno Kim (djkehh@gmail.com)
*/
@Controller
@RequestMapping("/path")
public class TestController extends SuperController implements MyInterface {
@RequestMapping("/home")
public String home() { return "index"; } // Quiz: home()에 접근하려면 url을 뭐라고 넣어야 하는가? 그것은 항상 보장되는가?
}
@RequestMapping("/super")
class SuperController {}
@RequestMapping("/superif")
interface MyInterface extends SuperInterface {}
@RequestMapping("/if")
interface SuperInterface {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment