具有Spring RESTController的端点的REST API层次结构

我具有一些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) {

        ...

    }

....

}


动漫人物
浏览 134回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java