我正在尝试覆盖mongo存储库的findAll(Pageable pageable)
方法,但不能完全实现。
我创建了一个名为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;
}
我想在原始存储库上调用findAll方法,以便我可以获取页面的内容然后进行修改。但是,这不起作用。我怎么能这样做?
答案 0 :(得分: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;
}
}