간단히 뷰만 보여주는 경우, 굳이 컨트롤러를 만들지 않고 뷰를 보여줄 수 있는 방법이 있다.
원래대로라면,
@RestController
public class HomeController{
@GetMapping("/hello")
public String hello(){
return "hello";
}
}
이렇게 컨트롤러를 직접 만들어줬었지만, 이렇게 달랑 뷰만 리턴하는 경우 굳이 컨트롤러를 이렇게 만들지 않아도 되는 방법이 있다는 말이다.
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewConrollers(ViewControllerRegistry registry){
registry.addViewConroller("/hello").setViewName("hello");
}
}