最近springboot开发需要设置个默认页面,就相当于我访问http://www.back.order.baidu.com要直接跳转到登录页面。

 

方案1:controller里添加一个"/"的映射路径

@RequestMapping("/")
public String index(Model model, HttpServletResponse response) {
    model.addAttribute("name", "simonsfan");
    return "/index";
}

方案二:设置默认的View跳转页面

@Configuration
public class DefaultView extends WebMvcConfigurerAdapter {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
        super.addViewControllers(registry);
    }
}

如上两种方式均可实现在springboot中设置默认页面跳转。


books 推荐阅读:elastic search搜索引擎实战demo:https://github.com/simonsfan/springboot-quartz-demo,分支:feature_es

books 推荐阅读:使用quartz实现定制化定时任务(包含管理界面)

Logo

一站式虚拟内容创作平台,激发创意,赋能创作,进入R空间,遇见同道,让优质作品闪耀发光。​

更多推荐