新聞中心
這篇文章將為大家詳細(xì)講解有關(guān)SpringBoot中怎么設(shè)置首頁跳轉(zhuǎn)功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
方案1:controller里添加一個"/"的映射路徑
@RequestMapping("/")public String index(Model model, HttpServletResponse response) { model.addAttribute("name", "simonsfan"); return "/index";}
方案二:設(shè)置默認(rèn)的View跳轉(zhuǎn)頁面
@Configurationpublic class DefaultView extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); super.addViewControllers(registry); }}
如上兩種方式均可實現(xiàn)在springboot中設(shè)置默認(rèn)頁面跳轉(zhuǎn)。
ps:SpringBoot設(shè)置默認(rèn)首頁
@Configurationpublic class DefaultView extends WebMvcConfigurerAdapter{ @Override public void addViewControllers(ViewControllerRegistry registry) { super.addViewControllers(registry); //主頁 registry.addViewController("/").setViewName("forward:/index"); } }
關(guān)于SpringBoot中怎么設(shè)置首頁跳轉(zhuǎn)功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
本文題目:SpringBoot中怎么設(shè)置首頁跳轉(zhuǎn)功能-創(chuàng)新互聯(lián)
路徑分享:http://fisionsoft.com.cn/article/cescod.html