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

您的位置:首頁技術文章
文章詳情頁

SpringBoot設置默認主頁的方法步驟

瀏覽:55日期:2023-04-02 14:08:40
1.若采用渲染引擎,JSP等VIEW渲染技術,可以通過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); }

此時不能通過配置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類中并未找到相關方法。也無其他解決方案。

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

到此這篇關于SpringBoot設置默認主頁的方法步驟的文章就介紹到這了,更多相關SpringBoot設置默認主頁內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 灌阳县| 中方县| 永宁县| 乌拉特中旗| 体育| 揭阳市| 铜梁县| 长寿区| 晋宁县| 嘉善县| 云和县| 罗定市| 堆龙德庆县| 潜山县| 舟曲县| 临海市| 庆城县| 高邮市| 阜南县| 旌德县| 黎川县| 普宁市| 南通市| 南丰县| 赤水市| 安岳县| 阳山县| 朝阳市| 四子王旗| 高平市| 皋兰县| 荔浦县| 五常市| 张掖市| 讷河市| 安庆市| 资中县| 祥云县| 玉环县| 农安县| 延吉市|