SpringBoot設置默認主頁的方法步驟
即:
@Configurationpublic class DefaultView extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController('/Blog').setViewName('forward:index.jsp'); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); super.addViewControllers(registry); }}
或者
@Controller@RequestMapping('/')public class IndexController { @RequestMapping('/Blog') public String index() { return 'forward:index.html'; }}2.若完全采用前后端分離的模式,即前端所有資源都放在addresourceHandler配置的路徑下
即
@Override protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler('/temples/**').addResourceLocations('classpath:/temples/'); super.addResourceHandlers(registry); }
此時不能通過配置addViewController的方式解決,會拋出異常
即
javax.servlet.ServletException: Could not resolve view with name ’forward:/temples/index.html’ in servlet with name ’dispatcherServlet’
只能通過response.redirect(“temples/index.html”)的方式重指向默認主頁,注:我在WebMvcConfigurationSupport類中并未找到相關(guān)方法。也無其他解決方案。
即
@Controller@RequestMapping('/')public class IndexController { @RequestMapping('/') public void index(HttpServletResponse response) throws IOException {response.sendRedirect('/temples/index.html'); }}3最后 最好通過nginx配置 不要在后臺項目代碼里添加前端的文件。
到此這篇關(guān)于SpringBoot設置默認主頁的方法步驟的文章就介紹到這了,更多相關(guān)SpringBoot設置默認主頁內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Android如何加載Base64編碼格式圖片2. 詳解Android studio 動態(tài)fragment的用法3. 解決Android studio xml界面無法預覽問題4. 基于android studio的layout的xml文件的創(chuàng)建方式5. 圖文詳解vue中proto文件的函數(shù)調(diào)用6. Spring Boot和Thymeleaf整合結(jié)合JPA實現(xiàn)分頁效果(實例代碼)7. 什么是python的自省8. 使用Android studio查看Kotlin的字節(jié)碼教程9. Vuex localStorage的具體使用10. Vue封裝一個TodoList的案例與瀏覽器本地緩存的應用實現(xiàn)

網(wǎng)公網(wǎng)安備