Я развиваю свое первое приложение, которое использует Spring Rest, у меня есть класс Veiculo.class
, Agencia.class
и Contato.class
. Когда я создал Veiculo
объект, который нуждается в списке, содержимое Agencia
и Spring
генерирует правильно гипермедию мои:Как установить список весной отдых
Entity
@Document
public class Veiculo{
@Id
private String id;
@Indexed(unique = true)
private String nome;
private String tipo;
@DBRef
List<Contato> contatos;
@DBRef
List<Agencia> agencias;
//getters and setters
}
Curl
[email protected]:~$ curl http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6
{
"nome" : "veiculo",
"tipo" : "tipo",
"_links" : {
"self" : {
"href" : "http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6"
},
"contatos" : {
"href" : "http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/contatos"
},
"agencias" : {
"href" : "http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias"
}
}
}
мне нужно задать список AGENCIA в пути /55a512a7ccf2bc55501419dc/agencias (является атрибутом Veiculo), но как я это делаю? я не нашел ни одного примера, что мне нужно
[email protected]:~$ curl http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias
{
"_links" : {
"self" : {
"href" : "http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias"
}
},
"_embedded" : {
"agencias" : [ ]
}
}
Когда я делаю POST
это происходит
[email protected]:~$ curl -i -X POST -H "Content-Type: application/json" -d '{"agencias": [{"nome": "um"}]}' http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias
HTTP/1.1 204 No Content
Server: Apache-Coyote/1.1
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Date: Tue, 14 Jul 2015 14:31:14 GMT
[email protected]:~$ curl http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias
{
"_links" : {
"self" : {
"href" : "http://localhost:8181/api/veiculos/55a50d42ccf2bc55501419d6/agencias"
}
},
"_embedded" : {
"agencias" : [ ]
}
Я попытался отправить массив, но когда я даю GET, возвращается ничего –