JAVA中的Thymeleaf传递模型

JAVA中的Thymeleaf传递模型,java,spring,list,spring-mvc,thymeleaf,Java,Spring,List,Spring Mvc,Thymeleaf,我试图创建一个简单的网页,其中动物有一些属性(如名称、动物类型和平衡)使用Thymeleaf。然而,我一直在遭受正确语法的困扰 我的Java代码是: @GetMapping("/multipleaccounts") public String multiple(Model model) { List bankAccounts = new ArrayList<>(); model.addAttribute("account", bankAccounts);

我试图创建一个简单的网页,其中动物有一些属性(如名称、动物类型和平衡)使用Thymeleaf。然而,我一直在遭受正确语法的困扰

我的Java代码是:

   @GetMapping("/multipleaccounts")
   public String multiple(Model model) {
   List bankAccounts = new ArrayList<>();
   model.addAttribute("account", bankAccounts);
   return "multiple";
   }
@GetMapping(“/multipleaccounts”)
公共字符串多(模型){
List bankAccounts=new ArrayList();
model.addAttribute(“账户”,银行账户);
返回“多次”;
}
在/multipleaccounts端点处,my ThymileAF代码有问题的部分:

<div th:each="element : ${account}" th:object="${element}">
    <p th:text="|My name is *{name}|"></p>
    <p th:text="|My balance is *{balance}|"></p>
    <p th:text="|My type is *{animalType}|"></p>
</div>`

`
我建议您不要使用原始类型,而是使用
列表正确解释此问题

简而言之,字符串串联的正确表示法如下:

<div th:each="a: ${account}">
    <p th:text="'|My name is ' + ${a.name} + '|'"></p>
    <p th:text="'|My balance is ' + ${a.balance} + '|'"></p>
     <p th:text="|My type is ' + ${a.animalType} + '|'"></p>
</div>

顺便问一下,您确定每个帐户都有
animalType

这将帮助您:

<div th:each="element : ${account}">
    <p th:text="'|My name is ' + ${element.name} + '|'"></p>
    <p th:text="'|My balance is ' + ${element.balance} + '|'"></p>
    <p th:text="'|My type is ' + ${element.animalType} + '|'"></p>
</div>


谢谢!基本上我的解决方案是有效的,我只是忘记了在列表中添加项目,我想从中删除一些元素。不过,我会留意你的建议。非常感谢。