Springboot |成功响应时,请在请求时使无效响应主体

发布于 2025-01-22 21:30:21 字数 1212 浏览 0 评论 0原文

像这样的Springboot项目中返回响应:

@GetMapping("/users")
public ResponseEntity<List<UserDto>> getUsers() {
    return ResponseEntity.ok(adminService.getUsers());
}

AdminService方法:

@Override
public List<UserDto> getUsers() {
    return userRepo.findAll()
            .stream()
            .map(this::convertEntityToDto)
            .collect(Collectors.toList());
}

我正在获取用户,但是在这样的成功主体之后,Null

[
{
    "id": 7,
    "title": "title",
    "description": "describtion",
    "email": "[email protected]",
    "creationDate": "2022-04-21T12:17:40.000+00:00",
    "plannedFinishDate": "2022-04-21T12:17:40.000+00:00"
},
{
    "id": 8,
    "title": "title2",
    "description": "describtion2",
    "email": "[email protected]",
    "creationDate": "2022-04-21T12:17:40.000+00:00",
    "plannedFinishDate": "2022-04-21T12:17:40.000+00:00"
}
]null

没有邮递员(在Alamofire的iOS Project中)尝试了此操作,但仍在这里。

Returning a response in SpringBoot project like this:

@GetMapping("/users")
public ResponseEntity<List<UserDto>> getUsers() {
    return ResponseEntity.ok(adminService.getUsers());
}

AdminService method:

@Override
public List<UserDto> getUsers() {
    return userRepo.findAll()
            .stream()
            .map(this::convertEntityToDto)
            .collect(Collectors.toList());
}

I'm getting users but with null after the success body like this:

[
{
    "id": 7,
    "title": "title",
    "description": "describtion",
    "email": "[email protected]",
    "creationDate": "2022-04-21T12:17:40.000+00:00",
    "plannedFinishDate": "2022-04-21T12:17:40.000+00:00"
},
{
    "id": 8,
    "title": "title2",
    "description": "describtion2",
    "email": "[email protected]",
    "creationDate": "2022-04-21T12:17:40.000+00:00",
    "plannedFinishDate": "2022-04-21T12:17:40.000+00:00"
}
]null

I tried this without postman (in iOS project with alamofire) but still null is here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文