【发布时间】:2018-10-22 22:42:16
【问题描述】:
我是 Thymeleaf 的新手。我无法使用 th:each 显示数据
我想显示这些数据
categoryDaoImpl.java
static {
Category category=new Category();
category.setId(1);
category.setName("Television");
category.setDescription("This is first Television in our home.");
category.setImageURL("rashed.jpg");
category.setActive(true);
categories.add(category);
}
在我的控制器 mycontroller.java 中
@RequestMapping(value= {"/","/home","/index"})
public String showHome(Model model) {
model.addAttribute("categories",categoryDao.list());
return "home";
}
这是我要显示数据的 html 页面。
<div class="list-group">
<a th:each="category : ${categories}" th:text="${category}" th:href="#" class="list-group-item active">Home</a>
</div>
更多信息,那些html代码没有显示在
页面来源
我也尝试了这个解决方案 thymeleaf - combined th:each with th:href 。 但它在我的 html 文件中不起作用,我也在使用 bootstrap 4。我该如何解决这个问题? 提前致谢。
【问题讨论】:
-
发生了什么?
-
它不显示任何类别附带的数据。
-
可能
category为空。最好也包含生成的 html。如果您不提供输入输出和预期输出等最少信息量,我们如何为您提供帮助。 -
看看我更新的问题,还有一个想法是,那些代码没有显示在“检查”或“页面源”中,这意味着至少不能在浏览器中工作,如何解决这个问题?
-
可以把categorydaoimpl类中list函数的代码贴出来吗?
标签: spring-mvc thymeleaf