Spring Data MongoDB自定义存储库方法实现

时间:2016-10-01 00:01:03

标签: spring spring-boot spring-data spring-data-mongodb

我按照here概述的说明为我的MongoDB存储库实现了自定义方法。但是,没有一个自定义方法似乎可用(In [107]: np.allclose(np.polyval(f,x),y) Out[107]: True findAllSeries似乎没有被春天找到。我检查了命名

SeriesRepository:

uploadSomeSeries

SeriesRepositoryCustom:

@RepositoryRestResource(collectionResourceRel = "series", path = "series", excerptProjection = SeriesProjection.class)
public interface SeriesRepository extends MongoRepository<Series, String>, SeriesRepositoryCustom {

    List<Series> findByWinnerId(@Param("id") String id);
}

SeriesRepositoryImpl:

public interface SeriesRepositoryCustom {

    ResponseEntity<Void> createSeries(Series series);
}

1 个答案:

答案 0 :(得分:1)

搞定了;通过this回答,我必须为我的存储库实现一个控制器,并将调用委托给自定义存储库中定义的方法:

@RepositoryRestController
public class SeriesController {

    private final SeriesRepository repository;

    @Autowired
    public SeriesController(SeriesRepository repo) {
        repository = repo;
    }

    @RequestMapping(value = "/series", method = RequestMethod.POST)
    public ResponseEntity<Void> create(@RequestBody Series series) {
        return repository.createSeries(series);
    }
}