我有一個使用SpringMVC和Thymeleaf的spring啓動項目。我在每個頁面上都包含一個layout.html中定義的頁腳。無論如何要在該頁腳上包含一個顯示每個頁面「狀態」的呼叫。通過這種方式瀏覽網站時,頁面頁腳將始終顯示所需的信息?Thymeleaf SpringMVC頁腳找不到控制器
我有一個REST控制器,把一個狀態對象:
@Controller
public class StatusController {
@RequestMapping(value = "/status", method = RequestMethod.GET)
public String get(Model model) {
Status status = new Stauts;
LocalDate lastUpdate = statusRepository.findByLastUpdate();
...
// do some work to update the status object
model.addAttribute(STATUS, status);
return "status";
}
我有一個在我的footer.html這個定義:
<div th:fragment="foot">
<div id="footer">
<div class="container">
<p class="muted credit">
<form action="refreshData" th:action="@{/status}" method="get"></form>
Last update status: <span th:text="${status.status}" class="text-info"></span>
</p>
</div>
</div>
</div>
,然後將每個頁面包含頁腳這樣:
...
<div th:include="layout :: foot"></div>
</body>
我把一個斷點在我的控制器和它的不叫,我總是得到這個excepti在頁面加載:
org.springframework.expression.spel.SpelEvaluationException: EL1007E:(POS 0):屬性或字段 '狀態' 不能爲null找到
我不知道控制器永遠不會被調用,因爲我必須使用類似jQuery的東西來進行Ajax調用,或者因爲我在layout.html中有這個,並且包含調用(這似乎不太可能)?
有關更改原因的說明在此處很有用 – StormeHawke 2014-10-09 15:33:30
但是從不調用控制器,因此Status對象從不返回。我將更新我的問題以顯示狀態對象在返回之前被實例化。 – sonoerin 2014-10-09 17:43:53