1 回答

TA貢獻1805條經驗 獲得超10個贊
當您使用ResponseEntity.ok(T body)返回類型時,ResponseEntity<T>因為它是一種將數據添加到ResponseEntity.
您需要通過ResponseEntity.ok()沒有返回Builder對象的參數創建的構建器對象。然后,您可以通過 body 方法自己添加數據。
所以你的代碼應該是這樣的
@GetMapping(path = "/users/notifications", consumes = "application/json", produces = "application/json")
public ResponseEntity<List<UserNotification>> userNotifications(
@RequestHeader(value = "Authorization") String authHeader) {
User user = authUserOnPath("/users/notifications", authHeader);
List<UserNotification> menuAlertNotifications = menuService
.getLast365DaysNotificationsByUser(user);
return ResponseEntity.ok().cacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS)).body(menuAlertNotifications);
}
添加回答
舉報