![](/img/trans.png)
[英]Static web resources in Spring Boot + Spring Security + Thymeleaf
[英]how to import static resources in front page with spring boot and thymeleaf when use @PathVariable
當我像下面那樣使用@RequestMapping時 ,我可以很好地獲取html渲染
@RequestMapping("/demo")
public String news() {
return "demo";
}
但是,當我添加參數@PathVariable(“ docid”)時 ,它會丟失所有靜態資源。
@RequestMapping("/single/{docid}")
public String single( @PathVariable("docid") String docid) {
return "demo";
}
在瀏覽器控制台中,它說無法加載資源:服務器以404()的ststus響應 。
我使用localhost:8080 / single / 123來啟動頁面,它將具有demo.html而沒有任何靜態資源,但是當我使用localhost:8080 / demo時 ,它運行良好。
我將import語句更改為th:src =“ @ {/ js / my.js}”,它仍然從localhost:8080 / single / js / my.js搜索靜態資源,該怎么辦?
附:我用Thymeleaf做模板。
將URL用作http:// host:port / single / 1001 ,沒有理由應該得到404。請確保在路徑(URL)中使用docid值。
我解決了,將th:fragment
所有import語句更改為絕對路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.