當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Boot静态资源映射规则
生活随笔
收集整理的這篇文章主要介紹了
Spring Boot静态资源映射规则
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
?
?
理論
演示
?
理論
使用Spring Boot:
? ? ? ? ?1. 創建Spring Boot應用,選中需要的模塊;
? ? ? ? ?2. Spring Boot已默認將這些場景配置好,只需要在配置文件中指定少量配置就可以運行起來;
? ? ? ? ? 3. 自己編寫業務代碼;
?
靜態資源文件:
? ? ? ? ? "classpath:/META-INF/resources/"
? ? ? ? ? "classpath:/resources/"
? ? ? ? ? "classpath:/static/"
? ? ? ? ? "classpath:/public"
? ? ? ? ? "/":當前項目的根目錄"
如localhost:8080/abc
就會去靜態資源文件里面找abc
?
演示
從webjars中導入jquery的maven
將
<dependency><groupId>org.webjars</groupId><artifactId>jquery</artifactId><version>3.3.1</version> </dependency>拷貝到pron.xml中!
把程序跑起來后,輸入連接:
http://localhost:8080/webjars/jquery/3.3.1/jquery.js
即可訪問文件:
在resources下創建一個public,如下圖,再創建一個頁面;
其中index.html源碼如下:
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>My Web</title><link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css"> </head><style type="">body {background: url(../img/background.jpg);height: 100%;}.container {position: relative;}.main-content {height: 780px;padding-bottom: 70px;}footer {height: 70px;width: 100%;position: absolute;bottom: 0;}footer {height: 70px;left: 0;bottom: 0;width: 100%;position: fixed;}</style><body> <!-- 導航頁 --> <nav class = "ui inverted attached segment m-padded-tb-mini m-shadow-small"><div class = "ui container"><div class = "ui inverted secondary stackable menu"><img class = "ui Mini circular image" src ="https://avatar.csdn.net/E/5/8/3_qq78442761.jpg"><h2 class = "ui teal header item">My Web</h2><a href="https://www.baidu.com" class="m-item item m-mobile-hide"><i class="mini computer icon"></i>點擊訪問我</a></div></div> </nav> <br> <br> <div class="m-container main-container"><div class="ui container main-content"><div class="ui stackable grid"><div class="six wide column"><div class="ui top attached segment"><div class="ui header">登錄后臺</div></div><div class="ui attached segment"><form method="post" ation="" class="ui form"><div class="ui labeled left icon input"><i class="computer icon"></i><input type="text" name="userName" placeholder="admin" ><a class="ui tag label">用戶名</a></div><br><br><div class="ui labeled left icon input"><i class="briefcase icon"></i><input type="password" name="passWord" placeholder="admin"><a class="ui tag label">密 碼</a></div><br><br><button class="fluid ui teal button" type="submit">提交</button></form></div><div class="ui segment"><div class="ui header">登錄記錄</div><table class="ui inverted teal table"><thead><tr><th>IP地址</th><th>時間</th><th>瀏覽器</th></tr></thead><tbody><tr><td>127.0.0.1</td><td>2018/3/8 00:00:00</td><td>谷歌</td></tr><tr><td>192.168.1.100</td><td>2018/3/8 00:00:11</td><td>未知</td></tr></tbody></table></div></div><div class="nine wide column"><div class="ui segment"><img src="https://picsum.photos/800/600/?random" alt="" class="ui rounded image"></div></div></div></div> </div><!--footer--> <footer class="ui inverted vertical segment"><div class="ui center aligned container"><div class="ui inverted divided stackable grid"></div><div class="ui inverted section divider"></div><p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright ? 2019 - 2020 </p></div> </footer></body> </html>運行截圖如下:
修改圖標,只要把ffavicon.ico文件放入靜態資源文件中即可!
如下:
總結
以上是生活随笔為你收集整理的Spring Boot静态资源映射规则的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt文档阅读笔记-QHostInfo官方
- 下一篇: Spring Boot中使用模板引擎引用