【问题标题】:How to send list of Long to rest controller Spring Boot如何将 Long 列表发送到休息控制器 Spring Boot
【发布时间】:2019-02-24 11:31:17
【问题描述】:

我需要在 Spring boot 中将 Long 对象列表从 Angular 发送到 Rest 控制器:

@PostMapping("/accept-friends")
    public ResponseEntity<Void> acceptFriendRequests(@RequestBody List<Long> friendRequestsIds)

这可能吗?

【问题讨论】:

  • 您想使用 GET 或 POST/PUT 方法吗?
  • 发表抱歉,忘记添加
  • 创建一个新 bean 并向该 bean 添加一个列表字段并映射该 bean
  • 看看this

标签: java spring rest spring-boot


【解决方案1】:

你可以这样使用它:

@PostMapping("/listData")
public ResponseEntity<Object> listData(@RequestBody List<?> completeList) {
  return new ResponseEntity<Object>(HttpStatus.OK)
}

据我所知,你不能保留ResponseEntity&lt;void&gt;

我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    是的,这是可能的,并且可以正常工作。

    @PostMapping("/accept-friends")
    public ResponseEntity<?> acceptFriendRequests(@RequestBody List<Long> friendRequestsIds) {
      return new ResponseEntity<>(HttpStatus.OK)
    }
    

    【讨论】:

      【解决方案3】:

      这里有 Angular 6 中的代码:

      getData(friendRequestsIds: number[]) {
          return this.http.post<Question>('/accept-friends', friendRequestsIds);
      }
      

      【讨论】:

        猜你喜欢
        • 2018-03-10
        • 2019-02-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-03
        • 2021-05-19
        • 2021-06-05
        • 1970-01-01
        相关资源
        最近更新 更多