2015-10-09 48 views
1

我試圖覆蓋mongo倉庫的findAll(Pageable pageable)方法,但不能完全做到這一點。如何覆蓋Mongo Repository的findAll方法

我創建了一個名爲MyRestRepository庫,看起來像這樣:

public interface MyRestRepository extends MongoRepository<Notify, String>, MyRestRepositoryCustom { 
    ... 
} 

裏面的MyRestRepositoryCustom界面我加入這個代碼:

@Modifying 
Page<Notify> findAll(Pageable pageable); 

最後我有MyRestRepositoryCustom實現:

public class MyRestRepositoryImpl implements MyRestRepositoryCustom { 
@Override 
public Page<Notify> findAll(Pageable pageable) { 
     // This doesn't work 
     Page<Notify> results = super.findAll(pageable); 
     // Do other stuff here to results... 
     return results; 

} 

我想打電話給t他在原始存儲庫中找到所有方法,以便我可以獲取頁面的內容,然後對其進行修改。但是,這不起作用。我怎樣才能做到這一點??

+0

是否要覆蓋它爲一個存儲庫或應用程序中的所有存儲庫? – jny

+0

對於一個特定的存儲庫。你能提供一些代碼和你的答案嗎? – Tometoyou

+0

我更新了答案 – jny

回答

0

MyRestRepositoryImpl必須延長SimpleMongoRepository。您不必在界面中定義findAll

public class MyRestRepositoryImpl extends SimpleMongoRepository implements MyRestRepositoryCustom { 
//call the super instructor 
public MyRestRepositoryImpl(....) { 
     super(....); 
} 

@Override 
public Page<Notify> findAll(Pageable pageable) { 
     // This doesn't work 
     Page<Notify> results = super.findAll(pageable); 
     // Do other stuff here to results... 
     return results; 

} 
} 
+0

這給出錯誤「編譯失敗.... [24,78]'{'預計' – Tometoyou

+0

什麼是24行? – jny

+0

對不起,這是'公共類MyRestRepository ...'行。我嘗試過在implements之前移動extends,而這似乎是做了一些事情,但是弄亂了其他的東西。我認爲需要一些仿製藥。很抱歉提出了很多問題,我不是本地Java開發人員! – Tometoyou