我正在写一个使用spark-java的小web应用程序。我使用thymeleaf作为模板引擎,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。
发布于 2019-05-09 23:40:21
我认为如果删除以下代码,它将会显示出来。
Spark.staticFiles.location("/templates");因为,ThymeleafTemplateEngine使用"/templates“下的文件。如果指定了staticFiles.location,则优先。因此,输出未模板化的index.html。
https://stackoverflow.com/questions/56008328
复制相似问题