Java 通过在Thymeleaf中使用for-each循环打印有序列表中的无序列表
我正在做一个项目,需要我在有序列表中打印无序列表 我当前拥有的代码仅显示第一个列表项,如下所示:Java 通过在Thymeleaf中使用for-each循环打印有序列表中的无序列表,java,html,list,foreach,thymeleaf,Java,Html,List,Foreach,Thymeleaf,我正在做一个项目,需要我在有序列表中打印无序列表 我当前拥有的代码仅显示第一个列表项,如下所示: 姓 姓 等等 getThemePark标记不是空的,但由于某些奇怪的原因不会显示 <ol> <th:block th:each="v : ${visitors}"> <li th:text = "${v.getSurName()} + ' '+ ${v.getFirstName()}" th:with ="
<ol>
<th:block th:each="v : ${visitors}">
<li th:text = "${v.getSurName()} + ' '+ ${v.getFirstName()}" th:with ="" >
<ul>
<li th:text = "${v} + ' '+ ${v.getThemeParkCode()} "></li>
</ul>
</li>
</th:block>
</ol>
如果有帮助的话,我的阵列就是这样构建的
private ArrayList<Visitor> fillVisitors() {
Visitor visitor4 = new Visitor("Name", "Surname");
visitor4.setYearOfBirth(int year);
visitors.add(visitor4);
visitors.get(3).addToWishList("nameOfAttraction");
visitors.get(3).addToWishList("nameOfAttraction");
...
提前谢谢 使用
th:text
覆盖它出现在的标记内部的任何内容。模板的内容可能如下所示:
<ol>
<li th:each="v : ${visitors}">
<span th:text="${v.getSurName()} + ' '+ ${v.getFirstName()}" />
<ul>
<li th:text = "${v} + ' '+ ${v.getThemeParkCode()}"></li>
</ul>
</li>
</ol>
你能为你的访客
类添加更多细节吗?@msucil刚刚添加了一堆我的代码,谢谢你的反馈!谢谢你帮助我!这似乎奏效了:)
private ArrayList<Visitor> visitors;
@PostConstruct
private void fillData() {
visitors = new ArrayList<>(fillVisitors());
}
public class Visitor extends Person{
private int yearOfBirth;
private int themeParkCode;
public Visitor(String firstName, String surName) {
super(firstName, surName);
wishList = new ArrayList<>();
themeParkCode = -1;
System.out.println();
}
public int getYearOfBirth() {
return yearOfBirth;
}
public void setYearOfBirth(int yearOfBirth) {
this.yearOfBirth = yearOfBirth;
}
public int getThemeParkCode() {
return themeParkCode;
}
public void setThemeParkCode(int themeParkCode) {
this.themeParkCode = themeParkCode;
}
public class Person {
private String firstName;
private String surName;
public Person(){}
public Person(String firstName, String surName) {
this.firstName = firstName;
this.surName = surName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getSurName() {
return surName;
}
public void setSurName(String surName) {
this.surName = surName;
}
<ol>
<li th:each="v : ${visitors}">
<span th:text="${v.getSurName()} + ' '+ ${v.getFirstName()}" />
<ul>
<li th:text = "${v} + ' '+ ${v.getThemeParkCode()}"></li>
</ul>
</li>
</ol>