我创建了一个这样的类用户类:
public class User {
/**
* The list of roles for the user
*/
private List<String> roles;
/**
* The login information
*/
private ICredentials credentials;
/*---- the constructors and getters/setters are omitted ---*/
}
ICredentials 接口:
public interface ICredentials {
}
一种实现:
public class LoginPassword implements ICredentials {
/**
* The login of the user
*/
protected String login;
/**
* The password of the user
*/
protected String password;
/*---- the constructors and getters/setters are omitted ---*/
}
现在,我创建了一个存储库来从凭据中查找用户:
public interface MongoUserRepository extends MongoRepository<User, String> {
List<User> findByCredentials(ICredentials credentials);
List<User> findByCredentialsEquals(ICredentials credentials);
}
Spring记录了这个(对于两个请求):org.springframework.data.mongodb.core.MongoTemplate [DEBUG] find using query: { "credentials" : { "login" : "test" , "password" : "test"}}
fields: null for class: class xxx.User in collection: user
而且什么都没找到……好像什么都没找到,因为“_class”属性没有写就是请求。我认为好的要求应该是:
{ "credentials" : {
"_class":"xxx.LoginPassword"
, "login" : "test" , "password" : "test"}}
我做错了什么吗?我错过了什么吗?
谢谢
我使用 spring mvc 3.2.0、spring-data-commons-core 1.4.0、spring-data-mongodb 1.1.1 和 mongo-java-driver 2.10.1(我已将所有库更新到最新版本以确保它不是已经修复的错误但没有成功)