0

私は持っている

@Document
public class Employee
{
 @Id
 Long empCode;
 String empSurname;
 String address;
// getters setters
}

それから私はMongoRepositoryの拡張を持っています

public interface EmployeeRepository extends MongoRepository<Employee, Long>
{
  EmployeeProject findAddressByEmpSurname(String surName);
}

EmployeeProject はプロジェクションです

public interface EmployeeProject 
{
    public List<String> getAddress();
}

呼んでいます

EmployeeProject param = employeeRepository.findAddressByEmpSurname("Smith");
param.getAddress().size(); -> Returns the first matched element only

最初の値だけでなく、一致したすべての値を文字列として返すには getAddress() が必要です。

どんな助けでも大歓迎です。ありがとう。PS: 生成されたクエリを MongoDB データベースで直接実行すると、すべてのドキュメントが返されます。コレクション射影が必要なようですが、正しい構文を取得できないようです。

4

0 に答える 0