Spring Data Rest中的关联

时间:2015-07-17 13:27:28

标签: java spring spring-data-mongodb spring-data-rest

我有一个名为Veículo的实体,另一个名为Agência的实体,Veículo有许多Agência,并希望进行此关联。但是,当我尝试关联 URI 时,我收到此错误。
任何人都可以帮我解释如何正确联系吗?

    daniela.morais@tusk:~$ curl -X POST -H "Content-Type:application/json" -d '{"nome": "Agencia"}' http://localhost:8181/api/agencias
    {
      "nome" : "Agencia",
      "createdBy" : "anonymousUser",
      "lastModifiedBy" : "anonymousUser",
      "createdAt" : "2015-07-17T13:20:10.266+0000",
      "lastModified" : "2015-07-17T13:20:10.266+0000",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8181/api/agencias/55a9010a44ae65cbf03ca4c2"
        }
      }
    }daniela.morais@tusk:~$ curl -X POST -H "Content-Type:application/json" -d '{"nome": "veiculo", "tipo": "tipo"}' http://localhost:8181/api/eiculos
    {
      "nome" : "veiculo",
      "tipo" : "tipo",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8181/api/veiculos/55a9015244ae65cbf03ca4c5"
        },
        "contatos" : {
          "href" : "http://localhost:8181/api/veiculos/55a9015244ae65cbf03ca4c5/contatos"
        },
        "agencias" : {
          "href" : "http://localhost:8181/api/veiculos/55a9015244ae65cbf03ca4c5/agencias"
        }
      }
    }
    daniela.morais@tusk:~$ curl -i -X PUT -H "Content-Type: text/uri-list" -d $'http://localhost:8181/api/agencias/55a9010a44ae65cbf03ca4c2' http://localhost:8181/api/veiculos/55a9015244ae65cbf03ca4c5/agencias
HTTP/1.1 404 Not Found
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
Content-Length: 0
Date: Fri, 17 Jul 2015 13:34:48 GMT

1 个答案:

答案 0 :(得分:2)

daniela.morais@tusk:~$ curl -X POST -H "Content-Type:application/json" -d '{"nome": "veiculo", "tipo": "tipo"}' http://localhost:8181/api/eiculos

看看这一行。 http://localhost:8181/api/eiculoshttp://localhost:8181/api/veiculos

或者http://localhost:8181/api/veiculos/55a9015244ae65cbf03ca4c5/agencias

应为http://localhost:8181/api/eiculos/55a9015244ae65cbf03ca4c5/agencias

看起来你有一个导致404

的拼写错误/拼写错误

其中eiculos不是veiculos