How to add links to Spring Data REST projections?

Deadly 提交于 2019-11-29 02:04:45
fortm

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;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!