我在理解一些基本代码时遇到问题

时间:2020-04-03 19:01:01

标签: spring rest api

这段代码让我头疼。也许这是一个la脚的问题。我已经使用REST API已有一段时间了。但是我从未使用过URI,也无法理解为什么我们在这里使用URI。为什么我们需要将URI对象放入响应中?

此方法正在使用后期映射。

@PostMapping(“ /用户”)

    long gameId = gameService.createGame(gamePostDTO.getPlayerIds());

    URI location = ServletUriComponentsBuilder
        .fromCurrentRequest()
        .buildAndExpand("1")
        .buildAndExpand(String.format("%d", gameId))
        .toUri();
    return ResponseEntity.created(location).build();
}

0 个答案:

没有答案