我正在尝试通过 Rest Api 以不同的格式(xml、json、rdf、jsonld)公开我的数据,并且我正在使用 Spring-Data-Rest-Framework,并且我知道可以在 Controller 中使用 @RequestMapping,但在 Spring Data Rest 中,我只有一个实体和一个使用 @RepositoryRestResource 表示法的存储库,不支持 @RequestMapping 表示法。
有人可以向我解释如何使用 Spring Data Rest 以不同格式公开数据吗?
我想指定 URL 末尾的格式,例如(?format=json 或 ?format=xml)
最佳答案
http://docs.spring.io/spring-data/rest/docs/current/reference/html/#representations.mapping
Currently, only JSON representations are supported. Other representation types can be supported in the future by adding an appropriate converter and updating the controller methods with the appropriate content-type.
您必须为 XML 或其他类型构建自己的转换器。定义内容类型的标准方法是在 Accept
header 中。如果您想使用覆盖,则需要添加过滤器来读取查询参数并设置 header 。
关于json - 如何在 Spring Data Rest 中使用内容协商?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39318010/