在application.propertis中配置
1
2
3
4
5
6
7
8
9
10
|
##端口號 server.port= 8081 ##默認前綴 spring.mvc.view.prefix=/ ## 響應頁面默認后綴 spring.mvc.view.suffix=.html # 默認值為 /** spring.mvc.static-path-pattern=/** # 這里設置要指向的路徑,多個使用英文逗號隔開,默認值為 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配置類
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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; /** * 手動配置靜態資源路徑 * */ @Configuration public class WebConfig extends WebMvcConfigurerAdapter{ @Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch( false ). setUseTrailingSlashMatch( true ); } } |
在controller中
1
2
3
4
5
6
7
8
|
/** * 跳轉index.html頁面 * @return */ @RequestMapping ( "/index" ) public String indexHtml() { return "index" ; } |
在瀏覽器中訪問地址
localhost:8081/index
以上所述是小編給大家介紹的Spring boot 默認靜態資源路徑與手動配置訪問路徑的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://www.cnblogs.com/dakewang/archive/2017/05/08/6824844.html