国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot設(shè)置默認(rèn)主頁的方法步驟

瀏覽:32日期:2023-04-02 14:08:40
1.若采用渲染引擎,JSP等VIEW渲染技術(shù),可以通過addViewController的方式解決。

即:

@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); }

此時(shí)不能通過配置addViewController的方式解決,會(huì)拋出異常

javax.servlet.ServletException: Could not resolve view with name ’forward:/temples/index.html’ in servlet with name ’dispatcherServlet’

只能通過response.redirect(“temples/index.html”)的方式重指向默認(rèn)主頁,注:我在WebMvcConfigurationSupport類中并未找到相關(guān)方法。也無其他解決方案。

@Controller@RequestMapping('/')public class IndexController { @RequestMapping('/') public void index(HttpServletResponse response) throws IOException {response.sendRedirect('/temples/index.html'); }}3最后 最好通過nginx配置 不要在后臺(tái)項(xiàng)目代碼里添加前端的文件。

到此這篇關(guān)于SpringBoot設(shè)置默認(rèn)主頁的方法步驟的文章就介紹到這了,更多相關(guān)SpringBoot設(shè)置默認(rèn)主頁內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 怀宁县| 东阿县| 农安县| 墨脱县| 邻水| 万山特区| 邻水| 襄垣县| 喀什市| 福海县| 盈江县| 庄河市| 威宁| 当阳市| 孟津县| 民勤县| 惠州市| 汽车| 新巴尔虎右旗| 渝中区| 洮南市| 子洲县| 彩票| 夏河县| 改则县| 福贡县| 乌兰察布市| 濮阳县| 托克托县| 宁都县| 香港| 启东市| 错那县| 岑巩县| 介休市| 仙居县| 竹山县| 蒲江县| 万山特区| 深水埗区| 景德镇市|