新聞中心
這篇文章將為大家詳細講解有關SpringBoot中怎么設置首頁跳轉(zhuǎn)功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。

方案1:controller里添加一個"/"的映射路徑
@RequestMapping("/")public String index(Model model, HttpServletResponse response) { model.addAttribute("name", "simonsfan"); return "/index";}
方案二:設置默認的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中設置默認頁面跳轉(zhuǎn)。
ps:SpringBoot設置默認首頁
@Configurationpublic class DefaultView extends WebMvcConfigurerAdapter{ @Override public void addViewControllers(ViewControllerRegistry registry) { super.addViewControllers(registry); //主頁 registry.addViewController("/").setViewName("forward:/index"); } }
關于SpringBoot中怎么設置首頁跳轉(zhuǎn)功能就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
網(wǎng)站名稱:SpringBoot中怎么設置首頁跳轉(zhuǎn)功能-創(chuàng)新互聯(lián)
標題來源:http://fisionsoft.com.cn/article/cescod.html


咨詢
建站咨詢
