假设我有以下课程
class Genre {
static hasMany=[author:Author]
}
class Author{
static hasMany=[books:Books]
}
class Books{
Author author
}
如何使用g:每个标签在gsp中打印?
答案 0 :(得分:9)
如果您想按作者显示所有图书,可以使用
<g:each var="author" in="${Author.list()}">
<p>Author: ${author.fullName}</p>
<ul>
<g:each var="book" in="${author.books}">
<li>${book.title}</li>
</g:each>
</ul>
</g:each>
干杯!