我正在开发一个项目,其中有两个表region
和district
。在region
我有:
+-------------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| name | blob | YES | | NULL | |
+-------------+------------+------+-----+---------+----------------+
并在district
我有:
+-------------+------------+------+-----+---------+----------------+
| 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
这是show
中的DistrictController
:
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
关闭,而不是显示Region.id
而是region.name
?
谢谢
答案 0 :(得分:3)
我假设您刚刚使用脚手架?因此,尝试覆盖Region中的toString(),例如
public String toString() {
name
}