场景
想要输入域名直接访问首页,比如输入lcoalhost:8081直接进某个页面
解决方案
我选择加个Configurer,代码如下(我是静态页面放在static中的):
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfigurer extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("/htmls/index.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
super.addViewControllers(registry);
}
}
本文介绍如何在SpringBoot中配置默认访问页面,通过创建WebConfigurer类并覆盖addViewControllers方法,实现输入域名直接跳转至指定页面的功能。
2426

被折叠的 条评论
为什么被折叠?



