Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何覆盖Mongo存储库的findAll方法_Spring_Spring Mvc - Fatal编程技术网

Spring 如何覆盖Mongo存储库的findAll方法

Spring 如何覆盖Mongo存储库的findAll方法,spring,spring-mvc,Spring,Spring Mvc,我正试图覆盖mongo存储库的findAll(Pageable-Pageable)方法,但是做不到 我创建了一个名为MyRestRepository的存储库,如下所示: public interface MyRestRepository extends MongoRepository<Notify, String>, MyRestRepositoryCustom { ... } 最后是MyRestRepositoryCustom的实现: public class MyRest

我正试图覆盖mongo存储库的
findAll(Pageable-Pageable)
方法,但是做不到

我创建了一个名为
MyRestRepository
的存储库,如下所示:

public interface MyRestRepository extends MongoRepository<Notify, String>, MyRestRepositoryCustom {
   ...
}
最后是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;

}
public类MyRestRepositoryImpl实现MyRestRepositoryCustom{
@凌驾
公共页findAll(可分页){
//这不管用
页面结果=super.findAll(可分页);
//在这里做其他的事情来获得结果。。。
返回结果;
}

我想在原始存储库上调用findAll方法,以便获取页面的内容,然后对其进行修改。但是,这不起作用。我如何才能做到这一点???

MyRestrepositionImpl
必须扩展
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;

}
}
公共类MyRestRepositoryImpl扩展SimpleMongoRepository实现MyRestRepositoryCustom{
//给超级教练打电话
公共MyRestrepositionImpl(…){
超级(……);
}
@凌驾
公共页findAll(可分页){
//这不管用
页面结果=super.findAll(可分页);
//在这里做其他的事情来获得结果。。。
返回结果;
}
}

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;

}
}
公共类MyRestRepositoryImpl扩展SimpleMongoRepository实现MyRestRepositoryCustom{
//给超级教练打电话
公共MyRestrepositionImpl(…){
超级(……);
}
@凌驾
公共页findAll(可分页){
//这不管用
页面结果=super.findAll(可分页);
//在这里做其他的事情来获得结果。。。
返回结果;
}
}

您想为应用程序中的一个存储库或所有存储库覆盖它吗?为一个特定的存储库。您能在回答中提供一些代码吗?我更新了答案您想为应用程序中的一个存储库或所有存储库覆盖它吗?为一个特定的存储库。您能为您的回答提供一些代码吗nswer?我更新了答案,第24行是什么?抱歉,这是
公共类MyRestRepository..
行。我尝试在实现之前移动扩展,这似乎做了一些事情,但会弄乱其他东西。我认为需要一些泛型。很抱歉问了很多问题,我不是本地Java开发人员!是的,ex倾向应该在实现之前。我很匆忙地键入。我更改了它。您还需要为泛型指定类型。第24行是什么?抱歉,这是
公共类MyRestRepository..
行。我尝试在实现之前移动扩展,这似乎做了一些事情,但会弄乱其他内容。需要一些我想是泛型。很抱歉问了这么多问题,我不是本地Java开发人员!是的,扩展应该在实现之前。我很匆忙地键入。我更改了它。您还需要为泛型指定类型。