将 bean 添加到配置中以添加视图控制器。这必须扩展WebMvcConfigurerAdapter
并简单地覆盖该addViewControllers
方法。
@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/manage/health");
registry.addViewController("/health").setViewName("forward:/manage/health");
}
}
或者,如果您想强制重定向使用addRedirectViewController
而不是addViewController
.
@Configuration
public class AliasWebConfig extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry) {
registry. addRedirectViewController("/", "/manage/health");
registry.addRedirectViewController("/health","/manage/health");
}
}