2017-02-22 80 views
0

我可以看到我的啓動模板使用百里香與春季啓動。春季啓動百里香無法加載css資源

當我請求http://localhost:8080/student bootstrap資源工作良好,但是當我請求包括一些像http://localhost:8080/student/3這樣的路徑變量時,bootstrap無法上傳。我從瀏覽器收到此錯誤請求方法:GET 狀態碼:400。它試圖請求像這樣的引導文件http://localhost:8080/student/bootstrap.css

我不認爲我有任何問題與聲明引導文件的路徑,因爲其他網頁工作正常。 而我的路徑是從指南作爲資源/靜態/ bootstrap.css 我沒有使用WebMvcConfig,我使用默認的彈簧安全。

@RequestMapping(value = "/student/{id}", method = RequestMethod.GET) 
public String izinEkle(Model model, @PathVariable int id) { 


    studentService.getStudentlById(id); 
    Izin izin = new Izin(); 
    model.addAttribute("izin",izin); 
    return "izinGiris"; 
} 

-

<head lang="en"> 

<title>HolyDayTracker</title> 
<link href="../static/bootstrap.css" th:href="@{bootstrap.css}" rel="stylesheet" media="screen"> 
<link href="../static/style.css" th:href="@{style.css}" rel="stylesheet"> 
<script src="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.min.js th:src="@{../webjars/jquery/2.1.4/jquery.min.js}"></script> 

+0

這似乎是程序試圖獲取路徑變量id作爲bootstrap.css。我想我的變量請求路徑有一些邏輯失敗。我很困惑。任何幫助,將不勝感激。謝謝。 – celnmeh

+1

[絕對vs相對URL]可能的重複(http://stackoverflow.com/questions/2005079/absolute-vs-relative-urls) – g00glen00b

+0

這裏的問題是'bootstrap.css'將是一個相對URL,並且'/student'和'/ student/3'是不同的級別,所以它們會相對指向'bootstrap.css'的不同位置。有很多解決方案,其中大部分可以在鏈接問題中找到。最常見的解決方案是使用絕對URL(如@shi所示)或在您的''部分設置''標籤,以便所有路徑的基本URL相同。 – g00glen00b

回答

0

嘗試添加斜線/在你thymeleaf HREF ATTR值。你不需要額外的href屬性,只需要:href就可以了。

<link th:href="@{/bootstrap.css}" rel="stylesheet" media="screen"> 
<link th:href="@{/style.css}" rel="stylesheet"> 
+0

非常感謝。我想我錯過了有關百里香參考文獻的重要觀點。沒有想到像這個解決方案,無論如何救了我。我很感激。但是,如果我刪除html href,我不能自動完成引導類。可能它是Ide的參考。 – celnmeh