测试这些示例获取映射的最佳和最简单的解决方案是什么?你能举一些简单的例子吗?
@GetMapping("/")
public List<UserDto> get() {
return userService.getUsers().stream().map((User user) -> toUserDto(user)).collect(Collectors.toList());
}
@GetMapping(path = "/{id}")
public HttpEntity<UserDto> findById(@PathVariable(name = "id") long id) {
User user = userService.unique(id);
if (user != null) {
return new ResponseEntity<>(toUserDto(user), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}