How can I simply add a link to a Spring Data REST Entity

后端 未结 3 1944
你的背包
你的背包 2021-01-02 07:20

I have my Entities with Spring Data JPA, but to generate stats about them, I use jOOQ in a Spring @Repository.

Since my methods return either a Li

3条回答
  •  渐次进展
    2021-01-02 07:36

    For manually create links see spring-hateoas-examples. Simplest wai is via new Resource if no DTO and extends ResourceSupport for DTO.

    Links to spring-data-rest managed entity I've customized similar to links to root resource:

    MyController implements ResourceProcessor> {
    
       @Override
       public Resource process(Resource resource) {
           resource.add(linkTo(methodOn(MyController.class)
               .myMethod(resource.getContent().getId(), ...)).withRel("..."));
           return resource;
    }
    

    And for paged resourses

    MyController implements ResourceProcessor>>
    

    The problem is when you need both, as yor cannot extends both this interface due to generic type erasure. As a hack I've created dummy ResourceController

提交回复
热议问题