1
使用mongodb的彈簧數據,如何指定存儲庫方法的返回類型以包含文檔中的特定屬性? 例如:springdata mongo存儲庫方法返回特定文檔屬性列表
@Document (collection = "foo")
class Foo {
String id
String name
... many more attributes
}
庫:如預期,並獲取唯一的名字從文檔屬性
interface FooRepository extends MongoRepository<Foo, String> {
@Query { value = "{}", fields = "{'name' : 1}" }
List<String> findAllNames()
}
以上findAllNames
作品。然而,彈簧數據返回對象是Foo
對象的string
表示,該對象具有值和剩餘屬性爲空的id和name屬性。 而不是Foo
對象,我需要取List<String>
這代表名字。
嗨,還有其他方法嗎? – TimSchwalbe