1
Optional<TicketUserDto> ticketuser=ticketUserDao.findByUserIdAndPassword(userId, password);

道:

@Repository
public interface TicketUsersDao extends MongoRepository<TicketUserDto, Serializable> {
    Optional<TicketUserDto> findByUserIdAndPassword(String userId, String password);
}

这是DTO定义

@Document(collection="ticket_users") 
public class TicketUserDto { 
    private String userId; 
    private String password; 

    public String getUserId() { return userId; } 
    public void setUserId(String userId) { this.userId = userId; } 

    public String getPassword() { return password; } 
    public void setPassword(String password) { this.password = password; }

    @Override public String toString() { 
        return "TicketUserDto [userId=" + userId + 
            ", password=" + password + "]"; 
    } 
}
4

2 回答 2

0

您的 find 方法应如下所示:

Optional<TicketUserDto> findOptionalByUserIdAndPassword(String userId, String password);

此外,您的类没有声明主键。为了使它工作,你应该重构你的类,如下所示:

@Document(collection="ticket_users") 
public class TicketUserDto { 
    @Id
    private String userId; 
    /* the other code remains untouched */
}

@Repository
public interface TicketUsersDao extends MongoRepository<TicketUserDto, String> {
    Optional<TicketUserDto> findOptionalByUserIdAndPassword(String userId, String password);
}
于 2018-10-02T09:09:00.023 回答
0

最后我知道我添加了@field 然后我得到了值

 @Field(value="userId")
private String userId;
@Field(value="password")
private String password;
于 2018-10-16T11:16:27.783 回答