Java Empty集合返回spring数据rest中的单个对象,而不是空数组
我正在为我的应用程序使用SpringDataREST 我已使用以下命令禁用hal json类型:-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
@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中的空收集?请帮助我您能包括您正在调用的存储库方法吗?或者你找到解决办法了吗?有解决办法吗?