【发布时间】:2014-02-14 11:24:38
【问题描述】:
我正在尝试使用 spring 数据调用自定义 mongoDB 查询,但查询没有被调用。
这是我的代码。
在控制器中:调用服务方法
List<UserProfile> gatheringMembers = userService.getUsersProfile(membersEmail);
这里是调用自定义 mongoDB 查询的服务方法
public List<UserProfile> getUsersProfile(List<String> emails){
return userProfileRepository.findAllUsersByEmail(emails);
}
这是我的 mongoDB 存储库界面
public interface UserProfileRepository extends MongoRepository<UserProfile, String>, UserProfileRepositoryCustom {
public UserProfile findByEmail(String email);
}
这里是界面
public interface UserProfileRepositoryCustom {
public List<UserProfile> findAllUsersByEmail(List<String> emails);
}
及其实现
public List<UserProfile> findAllUsersByEmail(List<String> emails) {
logger.info("getting all users profiles");
Query query = new Query(where("email").in(emails));
return mongoOperations.find(query, UserProfile.class);
}
当我运行代码时,我在控制器中得到空列表。 findByEmail 工作正常。谁能帮我看看这段代码有什么问题。
问候,
【问题讨论】:
标签: java mongodb spring-mvc spring-data