Custom response for root request int the Spring REST HATEOAS with both RepositoryRestResource-s and regular controllers

后端 未结 2 774
闹比i
闹比i 2020-12-13 02:43

Let\'s say I have two repositories:

@RepositoryRestResource(collectionResourceRel = \"person\", path = \"person\")
public interface PersonRepository extends          


        
相关标签:
2条回答
  • 2020-12-13 02:53
    @Component
    public class HelloResourceProcessor implements ResourceProcessor<RepositoryLinksResource> {
    
        @Override
        public RepositoryLinksResource process(RepositoryLinksResource resource) {
            resource.add(ControllerLinkBuilder.linkTo(HelloController.class).withRel("hello"));
            return resource;
        }
    }
    

    based on

    • http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.customizing-json-output
    • How to add links to root resource in Spring Data REST?
    0 讨论(0)
  • 2020-12-13 03:05

    You need to have a ResourceProcessory for your Person resource registered as a Bean. see https://stackoverflow.com/a/24660635/442773

    0 讨论(0)
提交回复
热议问题