Grails 在groovy中显示名称而不是id
我正在开发一个项目,其中有两个表,Grails 在groovy中显示名称而不是id,grails,groovy,Grails,Groovy,我正在开发一个项目,其中有两个表,region和district。在地区我有: +-------------+------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------+------+-----+---------+----------------+ | i
region
和district
。在地区
我有:
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| name | blob | YES | | NULL | |
+-------------+------------+------+-----+---------+----------------+
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| name | blob | YES | | NULL | |
| region_id | bigint(20) | NO | MUL | NULL | |
+-------------+------------+------+-----+---------+----------------+
在地区
我有:
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| name | blob | YES | | NULL | |
+-------------+------------+------+-----+---------+----------------+
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| name | blob | YES | | NULL | |
| region_id | bigint(20) | NO | MUL | NULL | |
+-------------+------------+------+-----+---------+----------------+
在地区视图中,将显示地区名称,但不显示地区名称:
Id 1
Name Community College
Description Community College
Homepage
Logo
Region ctv.Region : 1
Streams
这是分区控制器中的显示
:
def show = {
def districtInstance = District.get(params.id)
if(!districtInstance){
flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'district.label', default: 'District'), params.id])}"
redirect(action : "list")
}
else{
[districtInstance : districtInstance]
}
}
如何将我的show
闭包修改为other to而不是显示Region.id
我有Region.name
?
谢谢我想你只是在用脚手架吧?因此,请尝试覆盖区域中的toString(),例如
public String toString() {
name
}