我具有一些REST API的播放器资源URI:
http:// localhost:8080 / player
http:// localhost:8080 / player / 3 ----> id = 3的播放器资源的URI
我有用于游戏资源的以下URI:
http:// localhost:8080 / player / 3 / games
http:// localhost:8080 / player / 3 / games / 5 ---> id = 3的玩家(玩此游戏的玩家)的id = 5的游戏资源的URI。
使用Spring框架,我需要两个RestControllers,一个用于播放器资源,另一个用于游戏资源,但是使用@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) {
...
}
....
}
相关分类