我正在使用spring-data-mongo来检索我的notifications集合中的这些对象:
_id:ObjectId("123123123123")
1510067387875:Object
date:"1510067387875"
title:"Sample title"
text:"Sample Text"
_id:ObjectId("123223123123")
1110067387875:Object
date:"1110067387875"
title:"Sample title"
text:"Sample Text"因此,我定义了我的存储库类: NotificationRepository
@Repository
@Transactional("mongoTransactionManager")
@PersistenceContext(name = "mongodbEntityManager")
public interface NotificationRepository extends MongoRepository<NotificationMap, ObjectId> {
}和NotificationMap:
@Document(collection = "notifications")
public class NotificationMap {
@Id
private ObjectId _id;
private Map<String, Notification> map;
/**
* @return the map
*/
public Map<String, Notification> getMap() {
return map;
}
/**
* @param map the map to set
*/
public void setMap(Map<String, Notification> map) {
this.map = map;
}
public ObjectId get_id() {
return _id;
}
/**
* @param _id the _id to set
*/
public void set_id(ObjectId _id) {
this._id = _id;
}
}最后是Notification类:
public class Notification {
private long date;
private String title;
private String text;
private String dateString;但返回的是空对象。我应该如何访问这些信息
发布于 2019-06-13 05:15:47
NotificationMap似乎是不必要的。只需使用:
public interface NotificationRepository
extends MongoRepository<Notification, ObjectId> {https://stackoverflow.com/questions/52851827
复制相似问题