如何在中公开外部资源(不通过存储库管理)资源的根列表Spring Data REST 的?我按照以下模式定义了一个控制器休息金 https://github.com/olivergierke/spring-restbucks/blob/master/src/main/java/org/springsource/restbucks/payment/web/PaymentController.java
这可以通过实施来完成ResourceProcessor<RepositoryLinksResource>
.
以下代码片段将“/other”添加到根列表中
@Controller
@ExposesResourceFor(Other.class)
@RequestMapping("/others")
public class CustomRootController implements
ResourceProcessor<RepositoryLinksResource> {
@ResponseBody
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Resources<Resource<Other>>> listEntities(
Pageable pageable) throws ResourceNotFoundException {
//... do what needs to be done
}
@Override
public RepositoryLinksResource process(RepositoryLinksResource resource) {
resource.add(ControllerLinkBuilder.linkTo(CustomRootController.class).withRel("others"));
return resource;
}
}
应该添加
{
"rel": "others",
"href": "http://localhost:8080/api/others"
}
到您的根列表链接
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)