How to add links to Spring Data REST projections?

前端 未结 1 1813
滥情空心
滥情空心 2020-12-16 03:53

I have created a Spring Data Rest projection (not an excerpt projection) and need to add some links to it only as these links do not hold significance with other projections

相关标签:
1条回答
  • 2020-12-16 04:28

    It seems it is possible just to create a ResourceProcessor dedicated to a projection and I could create 3 ResourceProcessors one for each projection and one for entity itself and they get called depending on which projection is mentioned in URL.

    @Component
    public class UserProjectionResourceProcessor 
        implements ResourceProcessor<Resource<UserProjection>> {
    
        public static final String CANCEL_REL = "cancel";
    
        @Autowired
        private EntityLinks entityLinks;
    
        @Override
        public Resource<UserProjection> process(Resource<UserProjection> resource) {
    
            UserProjection userProjection = resource.getContent();   
            resource.add(entityLinks.linkFor(User.class).withRel(CANCEL_REL));              
            return resource;
        }
    }
    
    0 讨论(0)
提交回复
热议问题