【发布时间】:2021-08-05 15:48:26
【问题描述】:
我正在处理一个需要我在有序列表中打印无序列表的项目。
我目前的代码只显示第一个列表项,如下所示:
- 姓氏
- 姓氏 等等……
标签 getThemePark 不为空,但由于某些奇怪的原因不会显示。
<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>
这是确保我可以在 thymeleaf html 中使用访问者的代码
@RequestMapping("/6_ShowAllVisitors")
public String DisplayVisitors(Model model) {
model.addAttribute("visitors", visitors);
return "/6_ShowAllVisitors";
}
enter code here
如果有帮助,我的数组就是这样构建的。
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");
...
这就是我启动 MainController.Java 的方式
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;
}
这是父类操作Visitor:
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;
}
提前致谢!
【问题讨论】:
-
你能添加更多关于你的
Visitor类的细节吗? -
@msucil 刚刚添加了一堆我的代码,感谢反馈!
标签: java html list foreach thymeleaf