在课堂上访问对象 - 百里香

时间:2017-07-29 07:02:51

标签: spring thymeleaf

我有这样的课程:

public class Poetry {

    private String title;
    private Author author;

    // getters and setters
}

public class Author {

    private String name;

    // getters and setters
}

这就是我引用title的方式:

th:field="${poetry.title}"

但我如何参考poetry.author?我得到了这个例外:

Exception evaluating SpringEL expression: "poetry.author"
<body>
<div class="container">
  <div th:each="poetry : ${poetries}">
    <p th:text="${poetry.title}"></p>
    <p th:text="${poetry.content}"></p>
    <p th:text="${poetry.author}"></p>
  </div>
</div>
</body>

1 个答案:

答案 0 :(得分:0)

尝试访问作者中的字段,例如${poetry.author.name}