SpringBoot如何訪問html和js等靜態(tài)資源配置
SpringBoot訪問html和js等靜態(tài)資源配置
把靜態(tài)資源放到resources/static下,這是springboot靜態(tài)資源默認訪問路徑。
在瀏覽器直接ip:端口/靜態(tài)資源 就可以了
下面的廢話是好久之前寫的,不用看了。。。
SpringBoo推薦使用thymeleaf模板作用前端頁面展示,整體結(jié)構(gòu)如下所示:

這里我并沒有引入thymeleaf模板,所以頁面放在了pages目錄下。
application.yml配置如下:
server:
port: 9000
context-path: /sso
address: sso.server
spring:
mvc:
static-path-pattern: /**
# 默認值為 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/我設(shè)置了context-path,所以訪問的路徑前綴都要有/sso。
1:訪問html

在controller訪問html:
@RequestMapping("/user/login")
public String login(){
return "/pages/login.html";
}注解必須為@controller
2:訪問js

在頁面引入js文件:
<script src="/sso/js/jquery-3.3.1.js"></script>
訪問該頁面顯示js文件加載完成。

SpringBoot訪問不到j(luò)s,css等靜態(tài)資源問題
在網(wǎng)上找了一大部分回答都沒解決問題,所以記錄一下;
今天碰到這個問題,自己的thymeleaf導(dǎo)入文件的格式也沒啥問題,最后點擊maven中clean重啟下就可以了
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- springboot設(shè)置加載靜態(tài)資源的路徑(spring.resources.static-locations)
- SpringBoot中的static靜態(tài)資源訪問、參數(shù)配置、代碼自定義訪問規(guī)則詳解
- springboot攔截器不攔截靜態(tài)資源,只攔截controller的實現(xiàn)方法
- 關(guān)于SpringBoot攔截器攔截靜態(tài)資源的問題
- springboot應(yīng)用中靜態(tài)資源訪問與接口請求沖突問題解決
- SpringBoot2.x過后static下的靜態(tài)資源無法訪問的問題
- springboot+thymeleaf打包成jar后找不到靜態(tài)資源的坑及解決
- SpringBoot無法訪問/static下靜態(tài)資源的解決
- SpringBoot靜態(tài)資源及原理解析
相關(guān)文章
Spring?Cloud?OAuth2實現(xiàn)自定義token返回格式
Spring?Security?OAuth的token返回格式都是默認的,但是往往這個格式是不適配系統(tǒng)。本文將用一個接口優(yōu)雅的實現(xiàn)?Spring?Cloud?OAuth2?自定義token返回格式,需要的可以參考一下2022-06-06
解決idea中Springboot找不到BASE64Encoder或Decoder的jar包
這篇文章主要介紹了解決idea中Springboot找不到BASE64Encoder或Decoder的jar包,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
java語言實現(xiàn)權(quán)重隨機算法完整實例
這篇文章主要介紹了java語言實現(xiàn)權(quán)重隨機算法完整實例,具有一定借鑒價值,需要的朋友可以參考下。2017-11-11

