Accepting a Spring Data REST URI in custom controller

元气小坏坏 提交于 2019-12-03 04:52:07

As it turns out, I was on the right track with adding a converter, unfortunately I was doing it in the wrong configuration method.

I was able to get the desired functionality by moving my testConverter() bean to the RepositoryRestMvcConfiguration extension config class and then adding

@Override
public void configureConversionService(ConfigurableConversionService service) {
    service.addConverter(testConverter());
}

And working as intended. I feel a bit silly now for throwing that in the wrong spot in the first place, but hopefully this will help someone else out!

I am posting an answer based on my last comment.

Apparently the logic you require -- autoconverting URI from @RequestParam to a repository-managed entity -- is implemented in a few private methods of RepositorySearchController (see executeQueryMethod and prepareUris), so there's no easy way to get it in custom controllers.

You can try creating your own argument resolver with Spring HATEOAS. Look into how PersistentEntityResourceHandlerMethodArgumentResolver resolver is implemented. It resolved an entity based on its @BackendId.

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