首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在spring-data-mongodb中检索map mongo集合

在spring-data-mongodb中检索map mongo集合
EN

Stack Overflow用户
提问于 2018-10-17 17:44:17
回答 1查看 36关注 0票数 0

我正在使用spring-data-mongo来检索我的notifications集合中的这些对象:

代码语言:javascript
复制
_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

代码语言:javascript
复制
@Repository
@Transactional("mongoTransactionManager")
@PersistenceContext(name = "mongodbEntityManager")
public interface NotificationRepository extends MongoRepository<NotificationMap, ObjectId> {
}

和NotificationMap:

代码语言:javascript
复制
@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类:

代码语言:javascript
复制
public class Notification {
    private long date;
    private String title;
    private String text;
    private String dateString;

但返回的是空对象。我应该如何访问这些信息

EN

回答 1

Stack Overflow用户

发布于 2019-06-13 05:15:47

NotificationMap似乎是不必要的。只需使用:

代码语言:javascript
复制
public interface NotificationRepository
  extends MongoRepository<Notification, ObjectId> {
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52851827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档