Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring data rest 接受spring数据rest的头优先级_Spring Data Rest_Mithril.js - Fatal编程技术网

Spring data rest 接受spring数据rest的头优先级

Spring data rest 接受spring数据rest的头优先级,spring-data-rest,mithril.js,Spring Data Rest,Mithril.js,我正在使用mithril.js尝试spring数据rest。但是,我一直从存储库中获得xml响应,而不是json响应 我有一个存储库: @RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepository extends JpaRepository<Person, Long> { 然而,我在xml响应中得到了一个字符串列表 我试图检查以

我正在使用mithril.js尝试spring数据rest。但是,我一直从存储库中获得xml响应,而不是json响应

我有一个存储库:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {
然而,我在xml响应中得到了一个字符串列表

我试图检查以下来源,尽管我可能会看错并指出错误的来源:

发现mithril将accept标头设置为

xhr.setRequestHeader("Accept", "application/json, text/*")

但是,听起来SpringDataREST使用

@ResponseBody
@SuppressWarnings({ "unchecked" })
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, produces = {
        "application/x-spring-data-compact+json", "text/uri-list" })
public Resources<?> getCollectionResourceCompact(RootResourceInformation repoRequest, DefaultedPageable pageable,
@ResponseBody
@SuppressWarnings({“unchecked”})
@RequestMapping(值=基本映射,方法=RequestMethod.GET,生成={
“application/x-spring-data-compact+json”、“text/uri列表”})
公共资源getCollectionResourceCompact(RootResourceInformation repoRequest,DefaultedPageable pageable,

而不是

@ResponseBody
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET)
public Resources<?> getCollectionResource(final RootResourceInformation resourceInformation,
@ResponseBody
@RequestMapping(值=基本映射,方法=RequestMethod.GET)
公共资源getCollectionResource(最终根资源信息,
关于spring数据源:第210-213行


我的ajax请求有什么问题吗?

使用curl创建请求,并以您认为应该的方式工作。工作完成后,处理mithril部分。

mithril的
m.request
是一个非常轻量级的ajax包装器-在许多情况下,其他ajax实用程序可以正常工作,但mithril在没有深入分析的情况下以某种方式失败XHR的定制。同时,为了帮助解决Spring问题,了解Spring期望的请求头和Mithril实际发送的是什么将很有帮助…尝试从firefox发送请求,同样的问题。怀疑Mithril是否存在问题。或者,您能指出Mithril发送的上下文中有什么错误吗?尝试从firefo发送请求x、 同样的问题。怀疑mithril是否存在问题。或者,你能指出mithril发送的上下文中有什么错误吗?首先让它在Firefox或curl中工作。这样你就不必同时调试mithril和Spring。一旦它在curl中工作,就可以直接为mithril的请求添加适当的头。
@ResponseBody
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET)
public Resources<?> getCollectionResource(final RootResourceInformation resourceInformation,