我們如何在Spring Data Mongo中選擇特定的字段。我嘗試了以下,但我得到了從Foo
到String
的投射異常。如何在Spring Data MongoDB中僅返回查詢的特定字段?
使用@Query
@Query(value="{path : ?0}", fields="{path : 0}")
String findPathByPath(String path);
非@Query
String findPathByPath(String path);
這裏是文檔模型
@Document(collection = "foo")
public class Foo {
String name, path;
…
}
更多信息,你在說什麼? MongoDB沒有列。 – chrylis
我只想從我的模型中返回特定的字段。 在sql中它相當於 SELECT路徑FROM foo – richersoon