[英]Why I am getting the empty list while trying to fetch the query with the paramaterized generic
I am trying to fetch the List of the Type as depicted in the code below -: 我正在尝试获取以下代码中所示的类型列表-:
@Autowired
MongoTemplate mongotemplate;
@Override
public <T> List<T> getDetails(Query query, Class<T> queryClass) {
List<T> list= mongotemplate.find(query, queryClass);
return list;
}
}
This repository is called from the service as-: 该存储库从服务中调用为:
return messageSummaryImpl.getDetails(query, MessageSummaryDoc.class);
and the return Type of this function is List<MessageSummaryDoc>
并且此函数的返回类型为List<MessageSummaryDoc>
As the result of this is an Empty list,This code works fine when i dont use the generic function or say by directly calling the repository function from the service itself (mongorepository.find(query,Classexample.class))
Please suggest me what i am doing wrong. 由于这是一个空列表,当我不使用泛型函数或通过直接从服务本身调用存储库函数(mongorepository.find(query,Classexample.class))
说时,此代码可以正常工作(mongorepository.find(query,Classexample.class))
请告诉我做错了。
PS-: please don't ask me why i am not calling the repository directly(As this is the project requirement). PS-:请不要问我为什么我不直接调用存储库(因为这是项目要求)。
Either you have no entires that matches query or your mongotemplate does something fancy with query. 您可能没有匹配查询的整体,或者您的mongotemplate对查询做了一些幻想。
You stated that if you do (mongorepository.find(query,Classexample.class))
you got some data, but you are not using mongorepository
in given code but mongotemplate
so that is "false proof of concept" 你说,如果你这样做(mongorepository.find(query,Classexample.class))
你得到了一些数据,但你不使用mongorepository
在给定的代码,但mongotemplate
所以这是“概念的假证明”
Generics won't affect this issue by any means - they are gone on runtime anyway. 泛型不会以任何方式影响此问题-无论如何它们都在运行时运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.