Spring 使用 REST 延迟加载数据 DBRef - 500 服务器错误
Spring data DBRef lazy loading with REST - 500 server error
我正在使用 Spring 数据 MongoDB。
我有以下对象:
@Document(collection = "Notification")
public class Notification {
@Id
private String id;
@DBRef (lazy=true)
private User sender;
}
当我尝试使用以下方法 return 此对象时,我在浏览器控制台中收到 500 error
并且我看不到任何数据。
@RequestMapping(value = "/contactNotifications", method = RequestMethod.GET)
@ResponseBody
public List<Notification> getContactNotifications() {
List<Notification> notifications = notificationService.findByUser(user.getId());
return notifications;
}
但是,如果我删除 lazy=true
,它似乎确实有效。
如何在使用 lazy=true
时解决此问题?
我正在使用 Spring 数据 MongoDB。
我有以下对象:
@Document(collection = "Notification")
public class Notification {
@Id
private String id;
@DBRef (lazy=true)
private User sender;
}
当我尝试使用以下方法 return 此对象时,我在浏览器控制台中收到 500 error
并且我看不到任何数据。
@RequestMapping(value = "/contactNotifications", method = RequestMethod.GET)
@ResponseBody
public List<Notification> getContactNotifications() {
List<Notification> notifications = notificationService.findByUser(user.getId());
return notifications;
}
但是,如果我删除 lazy=true
,它似乎确实有效。
如何在使用 lazy=true
时解决此问题?