【发布时间】:2018-12-15 22:56:20
【问题描述】:
我有一些 REST API 的玩家资源的 URI:
http://localhost:8080/player/3 ----> id=3 的播放器资源的 URI
我有这个游戏资源的 URI:
http://localhost:8080/player/3/games
http://localhost:8080/player/3/games/5 ---> id=5 的游戏资源的 URI,用于 id = 3 的玩家(玩此游戏的玩家)。
使用 Spring 框架,我想要两个 RestController,一个用于玩家资源,另一个用于游戏资源,但使用 @RequestMapping 注释我有这个:
@RestController
@RequestMapping("${spring.data.rest.base-path}" + "/players")
public class PlayerRestResource {
@RequestMapping( method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public PlayerDto createPlayer(@RequestBody PlayerDTO newPlayerDTO) {
...
}
....
}
但我不知道如何为这样的 gameRestResource 使用 RequestMapping 注释并获取玩家的 id:
@RestController
@RequestMapping("${spring.data.rest.base-path}" + "/player/idplayer/games")
public class GameRestResource {
@RequestMapping( method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
public GameDto createGame(@RequestBody GameDTO newGameDTO) {
...
}
....
}
【问题讨论】:
标签: java rest spring-boot web