UrlMappings 中定义的 REST 资源导致 404

REST resources defined in UrlMappings results in 404

使用 grails 3.0.9,我定义了 2 个域:

Game -> hasMany plays
Play -> belongsTo game

我已将以下内容添加到我的 UrlMappings.groovy 文件中。

"/games"(resources: "game") {
  "/plays"(resources: "play")
}

使用 Postman,我在 http://localhost:8080/games 上做了一个 404

如果我删除 UrlMappings 并在 Game 域上放置一个 @Resource(uri='/games'),它会 returns 一个 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 不起作用。

我的理解是 UrlMappings 语法 "/games"(resources: "game") 自动生成关联的 RESTful 映射(并且仅生成映射),而使用 @Resource(uri='/games') 语法生成 controller/actions.

使用"/games"(resources: "game"),您仍然需要定义自己的控制器。看你这个问题的写法,感觉你没做过