国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

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

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

瀏覽:39日期:2023-04-12 18:44:13

WebMvcAutoConfiguration

添加資源映射:

public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) {logger.debug('Default resource handling disabled'); } else {Duration cachePeriod = this.resourceProperties.getCache().getPeriod();CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl();if (!registry.hasMappingForPattern('/webjars/**')) { this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{'/webjars/**'}).addResourceLocations(new String[]{'classpath:/META-INF/resources/webjars/'}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));}String staticPathPattern = this.mvcProperties.getStaticPathPattern();if (!registry.hasMappingForPattern(staticPathPattern)) { this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl));} } }

所有'/webjars/**'路徑 , 都去類(lèi)路徑下 classpath: /META-INF/resources/webjars/ 找資源, 所以就是

http://localhost:8080/webjars/jquery/3.5.1/jquery.js

能訪問(wèn)

/META-INF/resources/webjars/jquery/3.5.1/jquery.js 路徑的文件

1) webjars: 以jar包的方式引入靜態(tài)資源

什么是webjar?

搜索webjar, 可以將jquery用pom引入:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

引入, 正好對(duì)應(yīng)這個(gè)映射:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

結(jié)果是的:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

2) springboot對(duì)靜態(tài)資源的映射規(guī)則:

看代碼:

還是

WebMvcAutoConfiguration的這個(gè)方法

public void addResourceHandlers(ResourceHandlerRegistry registry) { if (!this.resourceProperties.isAddMappings()) { logger.debug('Default resource handling disabled'); } else { Duration cachePeriod = this.resourceProperties.getCache().getPeriod(); CacheControl cacheControl = this.resourceProperties.getCache().getCachecontrol().toHttpCacheControl(); if (!registry.hasMappingForPattern('/webjars/**')) { this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{'/webjars/**'}).addResourceLocations(new String[]{'classpath:/META-INF/resources/webjars/'}).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl)); } String staticPathPattern = this.mvcProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { this.customizeResourceHandlerRegistration(registry.addResourceHandler(new String[]{staticPathPattern}).addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())).setCachePeriod(this.getSeconds(cachePeriod)).setCacheControl(cacheControl)); } }}

進(jìn)去:

WebMvcProperties

private String staticPathPattern; private final WebMvcProperties.Async async; private final WebMvcProperties.Servlet servlet; private final WebMvcProperties.View view; private final WebMvcProperties.Contentnegotiation contentnegotiation; private final WebMvcProperties.Pathmatch pathmatch; public WebMvcProperties() { this.localeResolver = WebMvcProperties.LocaleResolver.ACCEPT_HEADER; this.format = new WebMvcProperties.Format(); this.dispatchTraceRequest = false; this.dispatchOptionsRequest = true; this.ignoreDefaultModelOnRedirect = true; this.publishRequestHandledEvents = true; this.throwExceptionIfNoHandlerFound = false; this.logResolvedException = false; this.staticPathPattern = '/**'; this.async = new WebMvcProperties.Async(); this.servlet = new WebMvcProperties.Servlet(); this.view = new WebMvcProperties.View(); this.contentnegotiation = new WebMvcProperties.Contentnegotiation(); this.pathmatch = new WebMvcProperties.Pathmatch(); }

addResourceLocations(WebMvcAutoConfiguration.getResourceLocations(this.resourceProperties.getStaticLocations())) 這里添加了資源的位置

public class ResourceProperties { private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{'classpath:/META-INF/resources/', 'classpath:/resources/', 'classpath:/static/', 'classpath:/public/'}; private String[] staticLocations; private boolean addMappings; private final ResourceProperties.Chain chain; private final ResourceProperties.Cache cache; public ResourceProperties() { this.staticLocations = CLASSPATH_RESOURCE_LOCATIONS; this.addMappings = true; this.chain = new ResourceProperties.Chain(); this.cache = new ResourceProperties.Cache(); }

'/**'訪問(wèn)當(dāng)前項(xiàng)目的任何資源, (靜態(tài)資源的文件夾) ,如果沒(méi)人處理,會(huì)默認(rèn)去以下幾個(gè)文件路徑下找[/code]復(fù)制代碼 代碼如下:// 靜態(tài)資源文件夾, 這幾個(gè)都可以存放靜態(tài)資源:

classpath:/META-INF/resources/classpath:/resources/'classpath:/static/'classpath:/public/

例如 localhost:8080/a/b.js , 可以到 /META-INF/resources/a/b.js 找

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

或者:

/resources/a/b.js找:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

或者類(lèi)路徑下/static/a/b.js找:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

或者/public/a/b.js下找

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

3)歡迎頁(yè)面: 靜態(tài)資源文件夾下的所有index.html頁(yè)面: 被 /**映射

http://localhost:8080/ 會(huì)到以上靜態(tài)資源文件夾中找index.html頁(yè)面

源碼有變化,我沒(méi)明白回頭再看

結(jié)果:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

路徑:

SpringBoot如何通過(guò)webjars管理靜態(tài)資源文件夾

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 久久综合色播 | 日本特级淫片免费看 | 欧美一级做 | 免费观看亚洲视频 | 国内精品99 | 亚洲综合在线视频 | 国内自拍网红在线综合 | 亚洲国产天堂久久九九九 | 多人伦精品一区二区三区视频 | 国产精品视频自拍 | 韩国三级大全久久网站 | 男人添女人下面免费毛片 | 国产精品99久久99久久久看片 | 亚洲视频一区二区三区 | 国产美女又黄又爽又色视频免费 | 欧美黄网站免费观看 | 波多野结衣中文无毒不卡 | 成年日韩片av在线网站 | 亚洲欧美日韩在线一区 | 成年人福利视频 | 一级特黄特色的免费大片视频 | 一级片免费观看视频 | 欧美毛片性视频区 | 国产亚洲福利一区二区免费看 | 亚洲国产中文字幕 | 亚洲精品久久九九精品 | 草草日 | 欧美另类69xxxxx视频 | 亚洲大片免费观看 | 久草热视频在线观看 | 欧美f| 99视频网址 | 国产一区二区免费在线观看 | 韩国毛片免费 | 久久性生大片免费观看性 | 国产三级小视频 | 日本欧美不卡一区二区三区在线 | 一区高清 | 国产精品99在线观看 | 亚洲羞羞裸色私人影院 | 久久精品国产亚洲高清 |