我有两个域类(驱动器和计算机)
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
我已经生成了我的 View ,并认为我需要编辑g.link,也许在Drive的show.gsp中。
感谢所有帮助。
最佳答案
默认情况下,它将显示toString()输出,因此将其覆盖以显示所需内容:
class Computer {
static hasMany = [drives:Drive]
String computerName
String toString() { computerName }
}
还要注意,默认情况下属性不是非空的,因此您可以在两个类中都省略nullable:false约束。
关于grails - Grails:如何编辑GSP( View /显示)以显示所需信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3240840/