[英]How to display message in webpage using thymeleaf + spark-java web framework?
我正在使用spark-java編寫一個小型Web應用程序。 我使用百萬美元作為模板引擎,intellij是我一直使用的IDE。 我面臨的問題是變量沒有在網頁中呈現,因為它應該具有。
我已將todaysdate
屬性傳遞給模板引擎
public void init() {
Spark.staticFiles.location("/templates");
get("/", (req, res) -> {
Map<String, Object> model = new HashMap<String, Object>();
DateModel dateModel = getDate();
String date = "Monday 6, May 2019";
model.put("todaysdate", date);
return render(model, "index");
});
}
private String render(Map<String, Object> model, String pageName){
return new ThymeleafTemplateEngine().render(
new ModelAndView(model, pageName)
);
}
我的html代碼包含以下代碼剪切
<div class="col-2 date" id="currentdate" th:text="${todaysdate}"></div>
但文本未顯示在網頁上。 Intellij說無法解決todaysdate
。
我認為如果刪除以下代碼將顯示它。
Spark.staticFiles.location("/templates");
因為,ThymeleafTemplateEngine使用“/ templates”下的文件。 如果指定了staticFiles.location,則優先。 因此,輸出未模板化的index.html。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.