gpt4 book ai didi

java - Spring Data Rest & Spring Data Envers : How to expose REST API for Repository that extends Revision Repository

转载 作者:搜寻专家 更新时间:2023-10-31 19:53:40 25 4
gpt4 key购买 nike

我在为我的存储库公开 RevisionRepository (Spring Data Envers) 端点时遇到问题,它扩展了 RevisionRepository 如下:

    @RepositoryRestResource(path = "disciplines", itemResourceRel = "disciplines")
public interface DisciplineRepository extends
RevisionRepository<Discipline, Integer, Integer>,
CrudRepository<Discipline, Integer>{

@RestResource(path = "findByName", rel = "findByName")
List<Discipline> findByName(String name);

}

只公开了findByName方法,有没有其他方法可以公开RevisionRepository中的方法?我也试图覆盖 DisciplineRepository 中的那些方法,但它不起作用。

谢谢你...

最佳答案

你必须编写一个自定义 Controller 方法来实现它,如下所示:

@Autowired
private DisciplineRepository disciplineRepository;

@RequestMapping(value = "/disciplines/{id}/changes", method = RequestMethod.GET)
public ResponseEntity<Resource<RevisionsObject>> getDisciplineRevisions(@PathVariable(value = "id")Discipline discipline) {
if (discipline != null) {
Revisions<Integer, Discipline> disciplineRevisions = disciplineRepository.findRevisions(discipline.getId());
return new ResponseEntity<>(new Resource<>(disciplineRevisions), HttpStatus.OK);
} else {
throw new ResourceNotFoundException();
}
}

关于java - Spring Data Rest & Spring Data Envers : How to expose REST API for Repository that extends Revision Repository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34196599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com