2017-07-29 76 views
0

我有类是这样的:访问类对象 - thymeleaf

public class Poetry { 
    private String title; 
    private Author author; 

    // getters and setters 
} 

public class Author { 
    private String name; 

    // getters and setters 
} 

,这是这样,我怎么是指标题:

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> 
+0

添加模板 –

回答

0

试试笔者之内访问现场,像${poetry.author.name}

+0

我得到异常评估SpringEL表达你的代码:“poetry.author.name”(新闻:18)日志:https://pastebin.com/6N9Ac9Qw – overmyhea

+0

碰到我的东西是'org.hibernate.LazyInitializationException:无法初始化代理 - 没有会话 - - 意味着你的作者没有初始化(它被设置为延迟加载)。要么正确初始化作者,要么将其设置为“@ Eager' –

+0

是的它的工作!感谢broo – overmyhea