Grails:如何编辑GSP(views / show)以显示所需信息

时间:2010-07-13 19:43:13

标签: grails

我有两个域类(驱动器和计算机)

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    static constraints = {
    computerName(nullable:false)
    }
}


class Drive {

    static belongsTo = Computer
    Computer computerName

    static constraints = {
    computerName(nullable:false)
    }
}

运行应用程序并单击DriveController时,计算机名称的下拉菜单显示如下:computer:1

我想要的输出是我实际为计算机输入的内容:1在我的实例中是Owner987

我已经生成了我的观点,并且相信我需要编辑g.link,可能在Drive的show.gsp中。

感谢所有帮助。

1 个答案:

答案 0 :(得分:4)

默认情况下,它会显示toString()输出,因此请覆盖它以显示您想要的内容:

class Computer {

    static hasMany = [drives:Drive]
    String computerName

    String toString() { computerName }
}

另请注意,默认情况下属性不为null,因此您可以在两个类中省略nullable:false约束。