spring - @Document(collection = "Test") 在 MongoRep

我正在尝试使用 java 的泛型创建通用的 mongo 存储库。 我已经定义存储库如下。

public interface ICentroRepository<T extends Serializable, ID extends 
Serializable> extends MongoRepository<T, ID> {  
}

我定义文档实体如下

@Document(collection = "mycollectionName")
public class SkuItem implements Serializable {

@Id
private String _id;

String title;
//Getter and Setter of _id and title
}

但它总是选择可序列化的集合名称(在 ICentroRepository 中扩展 T 的接口(interface)/类,而不是在@Document 的集合中定义的值。 谁能帮我设计我的通用 mongo 存储库? 非常感谢您。 :) :)

最佳答案

public interface ICentroRepository<T extends Serializable, ID extends 
Serializable> extends MongoRepository<T, ID> {  
}

public interface ICentroRepository extends MongoRepository<SkuItem, ID> {  
}

关于spring - @Document(collection = "Test") 在 MongoRepository 中不起作用 - Spring 数据 - mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45803211/

相关文章:

vue.js - token 失效时自动注销用户

azure - Azure WebApp 是否自动进行速率限制/DOS 保护?

r - 无法删除文件 - 打开我的 Rstudio

c# - Signalr net client On 事件泛型类型参数

python-3.x - Python 3 文件共享变量

php - 找不到属性 Application\Sonata\NewsBundle\Entity\P

javascript - 如何将样式(css)和js添加到 Handlebars 文件?

c# - 更改 RedirectUri、Nginx 和 ASP.NEt Core

selenium - 使用 SendKeys 向 IE 11 发送 '@' 特殊字符

apache-spark - Kafka 结构化流 java.lang.NoClassDefFoun