Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/331.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
Java Empty集合返回spring数据rest中的单个对象,而不是空数组_Java_Spring_Rest_Spring Mvc_Spring Data Rest - Fatal编程技术网

Java Empty集合返回spring数据rest中的单个对象,而不是空数组

Java Empty集合返回spring数据rest中的单个对象,而不是空数组,java,spring,rest,spring-mvc,spring-data-rest,Java,Spring,Rest,Spring Mvc,Spring Data Rest,我正在为我的应用程序使用SpringDataREST 我已使用以下命令禁用hal json类型:- @Override public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) { config.useHalAsDefaultJsonMediaType(false); } links": [ { "rel": "self", "hr

我正在为我的应用程序使用SpringDataREST

我已使用以下命令禁用hal json类型:-

 @Override
 public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

  config.useHalAsDefaultJsonMediaType(false);
}
links": [

    {
        "rel": "self",
        "href": "http://localhost:8081/users"
    },
    {
        "rel": "profile",
        "href": "http://localhost:8081/profile/users"
    },
    {
        "rel": "search",
        "href": "http://localhost:8081/users/search"
    }

],
"content": [

    {
        "id": 2,
        "key": "wire",
        "name": "Wireless",
        "content": [ ],
        "links": [
            {
                "rel": "self",
                "href": "http://localhost:8081/users/2"
            },
            {
                "rel": "user",
                "href": "http://localhost:8081/users/2"
            }
        ]
    }..
对于空对象,我的响应如下所示:-

{

    "links": [
        {
            "rel": "self",
            "href": "http://localhost:8081/users"
        },
        {
            "rel": "profile",
            "href": "http://localhost:8081/profile/users"
        },
        {
            "rel": "search",
            "href": "http://localhost:8081/users/search"
        }
    ],
    "content": [
        {
            "relTargetType": "com.sample.User",
            "collectionValue": true,
            "value": [ ]
        }
    ]

}
当我有用户数据时,它如下所示:-

 @Override
 public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {

  config.useHalAsDefaultJsonMediaType(false);
}
links": [

    {
        "rel": "self",
        "href": "http://localhost:8081/users"
    },
    {
        "rel": "profile",
        "href": "http://localhost:8081/profile/users"
    },
    {
        "rel": "search",
        "href": "http://localhost:8081/users/search"
    }

],
"content": [

    {
        "id": 2,
        "key": "wire",
        "name": "Wireless",
        "content": [ ],
        "links": [
            {
                "rel": "self",
                "href": "http://localhost:8081/users/2"
            },
            {
                "rel": "user",
                "href": "http://localhost:8081/users/2"
            }
        ]
    }..
我关心的是有空的内容集合,如下所示:-

{

    "links": [
        {
            "rel": "self",
            "href": "http://localhost:8081/users"
        },
        {
            "rel": "profile",
            "href": "http://localhost:8081/profile/users"
        },
        {
            "rel": "search",
            "href": "http://localhost:8081/users/search"
        }
    ],
    "content": []

}

如何处理spring数据rest中的空收集?请帮助我

您能包括您正在调用的存储库方法吗?或者你找到解决办法了吗?有解决办法吗?