grails - Grails GSP格式问题

标签 grails gsp

我正在尝试Grails,并且在使用GSP时遇到了一些问题。

我有三个类(class),分别是:作者,书籍和奖章。一位作者可以有很多本书,每本书可以有多个奖项。以下是域 Controller :

class Author {

    String  authorName
    static  hasMany = [books : Book]

}

class Book {

    String      bookName
    BigDecimal  price

    static      belongsTo=[author : Author]
    static      hasMany=[awards: Award]
}

class Award {

    String  awardName
    Date    awardDate

    static  belongsTo = [book : Book]

}

以下是我的GSP:
        <table>
            <th >Author Name</th>
            <th >Books</th>
            <th >Awards</th>

            <g:each in="${authorList}" var="author" status="i">
                <tr>

                    <td> ${author.authorName} </td>
                    <td> ${author.books} </td>
                    <td> ${author.books.awards} </td>
                </tr>
            </g:each>
        </table>

目前显示:

书籍如:[书籍2,书籍1]
奖项为:[[],[奖项1]]

我想将它们显示为:
图书:
1.书2
2.书1

奖项:
1。
2.奖励1

我是否可以将Book和Award都放入一个对象并用于迭代?

先感谢您。

最佳答案

${author.books}${author.books.awards}是SET,因此您可以

<g:each in="${author.books}" var="book">
    <tr>
        <td> ${book?.bookName} </td>
        <td> ${book?.price} </td>
    </tr>
</g:each>

关于grails - Grails GSP格式问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43828884/

相关文章:

grails - 重写 Grails 内置库?

grails - Grails执行查询

grails - 在GSP中显示动态表,其中列和数据在运行时出现

grails - 选择列表选项的首选位置在哪里

internet-explorer - grails必需的标记在IE8上不起作用

java - 如何判断当前 tx (Hibernate) 中是否删除了 Grails/GORM 域实例?

hibernate - 多个 Grails 应用程序会造成 Ehcache 冲突

grails - Grails是否可以保护.gsp文件?

grails - GSP-为选择标记选项设置整数值

grails - grails-org.hibernate.QueryException(无法解析属性)