Spring boot 默認(rèn)靜態(tài)資源路徑與手動配置訪問路徑的方法
更新時間:2017年05月08日 14:29:22 作者:hello_dakewang
這篇文章主要介紹了Spring boot 默認(rèn)靜態(tài)資源路徑與手動配置訪問路徑的方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
在application.propertis中配置
##端口號 server.port=8081 ##默認(rèn)前綴 spring.mvc.view.prefix=/ ## 響應(yīng)頁面默認(rèn)后綴 spring.mvc.view.suffix=.html # 默認(rèn)值為 /** spring.mvc.static-path-pattern=/** # 這里設(shè)置要指向的路徑,多個使用英文逗號隔開,默認(rèn)值為 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/ spring.resources.static-locations= classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/****/
如果自定義訪問路徑則需要添加WebConfig配置類
package com.dakewang.config; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * 手動配置靜態(tài)資源路徑 * */ @Configuration public class WebConfig extends WebMvcConfigurerAdapter{ @Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch(false). setUseTrailingSlashMatch(true); } }
在controller中
/** * 跳轉(zhuǎn)index.html頁面 * @return */ @RequestMapping("/index") public String indexHtml() { return "index"; }
在瀏覽器中訪問地址
localhost:8081/index
以上所述是小編給大家介紹的Spring boot 默認(rèn)靜態(tài)資源路徑與手動配置訪問路徑的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
探究Java常量本質(zhì)及三種常量池(小結(jié))
這篇文章主要介紹了探究Java常量本質(zhì)及三種常量池(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09MyBatis學(xué)習(xí)教程之開發(fā)Dao的方法教程
這篇文章主要給大家介紹了關(guān)于MyBatis開發(fā)Dao的相關(guān)資料,使用Mybatis開發(fā)Dao,通常有兩個方法,即原始Dao開發(fā)方法和Mapper接口開發(fā)方法。文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面來一起看看吧。2017-07-07Java?Spring?AOP源碼解析之事務(wù)實現(xiàn)原理
這篇文章主要為大家介紹了Java?Spring?AOP事務(wù)實現(xiàn)原理,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助2022-01-01