1

我正在开发一个项目,其中有两个表,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    |                |
+-------------+------------+------+-----+---------+----------------+

在 District 视图中,将显示该地区的名称,但不显示 Region 名称:

Id  1
Name    Community College
Description Community College
Homepage    
Logo    
Region  ctv.Region : 1
Streams 

这是showDistrictController

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?谢谢

4

1 回答 1

3

我假设您只是使用脚手架?所以尝试在 Region 中覆盖 toString(),例如

public String toString() {
   name
}
于 2012-07-05T03:08:02.030 回答