Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 在groovy中显示名称而不是id_Grails_Groovy - Fatal编程技术网

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
}