我剛剛開始使用Spring Data Rest,並且想要爲在MongoDB中索引文本的字段公開查找器。我有以下索引定義:MongoDBs全文搜索可以與Spring Data REST一起使用嗎?
@TextIndexed
private String title;
並驗證索引是否已創建。我已經創建的存儲庫定義查找方法:
public interface ContentRespository extends MongoRepository<Content, String> {
public Page<Content> findByTitle(@Param("title") TextCriteria title, @Param("pageable") Pageable pageable);
}
通過調用REST API網址:
http://localhost:8080/contents/search/findByTitle?title=test
我收到以下錯誤:
2017-01-19 13:16:41.831 ERROR 16705 --- [nio-8080-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.repository.support.QueryMethodParameterConversionException: Failed to convert test into org.springframework.data.mongodb.core.query.TextCriteria!] with root cause
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [@org.springframework.data.repository.query.Param org.springframework.data.mongodb.core.query.TextCriteria]
at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324) ~[spring-core-4.3.4.RELEASE.jar:4.3.4.RELEASE]
....
什麼是正確的調用REST API的方式?我找不到任何有關它的文檔。或者如何爲TextCriteria編寫一個轉換器?
是的,有沒有任何例子如何寫這樣的轉換器? –
當然。谷歌將幫助找到它。但是,通過某些類包裝內容庫會更容易 –
當然,我可以谷歌它,但我的問題更多的是通過REST API訪問_TextIndexed_字段的默認方式。 _Indexed_字段的其他查找方法正在開箱即用。編寫一個轉換器將是第二個選項 –