Tag: spring hateoas

何时使用@RestController vs @RepositoryRestResource

我一直在研究如何在REST中使用Spring的各种示例。 我们的最终目标是Spring HATEOAS / HAL设置 我已经看到了在Spring中呈现REST的两种不同的方法 通过Controller中的@RestController 通过@RepositoryRestResource中的@RepositoryRestResource 我正在努力寻找的东西是为什么你会用另一个。 当试图实施最好的HAL? 我们的数据库后端是Neo4j。

我可以使自定义控制器镜像Spring-Data-Rest / Spring-Hateoas生成的类的格式吗?

我试图做一些我认为应该很简单的事情。 我有一个Question对象,用spring-boot,spring-data-rest和spring-hateoas来设置。 所有的基本工作正常。 我想添加一个自定义控制器返回一个List<Question>与格式完全相同的格式,我的Repository的/questions URL做,以便两者之间的响应是兼容的。 这是我的控制器: @Controller public class QuestionListController { @Autowired private QuestionRepository questionRepository; @Autowired private PagedResourcesAssembler<Question> pagedResourcesAssembler; @Autowired private QuestionResourceAssembler questionResourceAssembler; @RequestMapping( value = "/api/questions/filter", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody PagedResources<QuestionResource> filter( @RequestParam(value = "filter", required = false) String filter, Pageable p) { // Using queryDSL here […]