使用grails 3.0.9,我已经定义了2个域:
Game -> hasMany plays
Play -> belongsTo game
我已将以下内容添加到我的UrlMappings.groovy文件中。
"/games"(resources: "game") {
"/plays"(resources: "play")
}
使用邮递员,我正在进行http://localhost:8080/games
,我得到404
。
如果我删除了UrlMappings并在@Resource(uri='/games')
域上放置Game
,则会按预期返回200。这是我运行url-mappings-report时得到的结果:
Dynamic Mappings
| * | ERROR: 404 | View: /notFound |
| * | ERROR: 500 | View: /error |
| * | / | View: /index |
| * | /${controller}/${action}?/${id}?(.${format)? | Action: (default action) |
Controller: game
| GET | /games/create | Action: create |
| GET | /games/${id}/edit | Action: edit |
| POST | /games | Action: save |
| GET | /games | Action: index |
| DELETE | /games/${id} | Action: delete |
| PATCH | /games/${id} | Action: patch |
| PUT | /games/${id} | Action: update |
| GET | /games/${id} | Action: show |
Controller: play
| GET | /games/${gameId}/plays/create | Action: create |
| GET | /games/${gameId}/plays/${id}/edit | Action: edit |
| POST | /games/${gameId}/plays | Action: save |
| GET | /games/${gameId}/plays | Action: index |
| DELETE | /games/${gameId}/plays/${id} | Action: delete |
| PATCH | /games/${gameId}/plays/${id} | Action: patch |
| PUT | /games/${gameId}/plays/${id} | Action: update |
| GET | /games/${gameId}/plays/${id} | Action: show |
不确定为什么UrlMappings无效。
答案 0 :(得分:1)
我的理解是UrlMappings语法"/games"(resources: "game")
自动生成关联的RESTful映射(并且只生成映射),而使用@Resource(uri='/games')
语法生成控制器/操作。
使用"/games"(resources: "game")
,您仍需要定义自己的控制器。你写这个问题的方式,让我感觉你还没有完成这个。