【问题标题】:How to post data to the table from POSTMAN client如何从 POSTMAN 客户端将数据发布到表中
【发布时间】:2015-04-29 17:52:54
【问题描述】:

我正在 spring-data-rest 中开发一个购物车应用程序。我正在从 POSTMAN 客户端测试我的应用程序。在我的应用程序中,我有 Cart 表和 Cart_item 表。 Cart_item 表有 cart_id 字段,该字段将从 Cart 中获取 id。我能够将数据分别放入 Cart 和 Cart_item 。但我对单独放置数据不感兴趣。我可以在单个 JSON 中发送购物车数据和购物车项目数据。

我可以使用以下 JSON 插入购物车表: 邮递员中的购物车网址:http://localhost:8080/sportsrest/carts

{
  "date": "2015-10-10",
  "totalAmount": 1000,
   "createdAt": "2015-04-06T18:30:00.000+0000",
   "updatedAt": "2015-04-09T18:30:00.000+0000",
   "sport":"http://localhost:8080/sportsrest/sports/1",
   "user":"http://localhost:8080/sportsrest/users/9090909090",
   "tenant": "http://localhost:8080/sportsrest/tenants/2"
  }

cart_item:http://localhost:8080/sportsrest/cartItems

  {
  "rate": 500,
  "quantity": 2,
  "amount": 1000,
  "createdAt": "2015-04-12T23:40:00.000+0000",
  "updatedAt": "2015-04-14T21:35:20.000+0000",
   "merchandise": "http://localhost:8080/sportsrest/merchandises/10",
  "cart":"http://localhost:8080/sportsrest/carts/901",
  "merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"
  }

如何通过单个 JSON 请求将数据放入 cart 和 cart_item 表中?

我尝试了以下方式,但正在添加购物车,但 cart_item 未在 cart_item 表中创建:URL:http://localhost:8080/sportsrest/carts

  {
   "http://localhost:8080/sportsrest/cartItems":
      {
       "rate": 50,
       "quantity": 1,
       "amount": 50,
       "createdAt": "2015-04-12T23:40:00.000+0000",
       "updatedAt": "2015-04-14T21:35:20.000+0000",
       "merchandise": "http://localhost:8080/sportsrest/merchandises/10",
       "merchandiseType":"http://localhost:8080/sportsrest/merchandiseTypes/1"
        },
     "date": "2015-10-10",
     "totalAmount": 99898,
     "createdAt": "2015-04-06T18:30:00.000+0000",
     "updatedAt": "2015-04-09T18:30:00.000+0000",
     "sport":"http://localhost:8080/sportsrest/sports/1",
     "user":"http://localhost:8080/sportsrest/users/9090909090",
     "tenant": "http://localhost:8080/sportsrest/tenants/2"
   }

谁能帮帮我..

提前致谢

【问题讨论】:

  • 我认为这是两个单独的请求,需要在邮递员中单独创建,或者您可以使用 curl/bash 自动发送这两个请求?希望有帮助
  • @Filype 感谢重播。 cart_item 表有一个字段 cart_id,它引用了 cart 表中的 id。你能举个例子,我如何在我的场景中使用 curl 发送请求?
  • @Filype 我如何从 POSTMAN 测试它

标签: mysql json spring-data-rest postman


【解决方案1】:

Postman 是与 API 对话的绝佳工具,但它无法完成您需要做的事情。看来您需要的不仅仅是构建一个 HTTP 请求(这就是邮递员所做的)。

我看到的方法是:

  • 向购物车 API 发送 PUT
  • 存储响应中的 card_id
  • 使用card_id(来自第一个请求)向 cart_item 发送 PUT

在邮递员之外有很多方法可以做到这一点,如果你在 linux/mac 环境中,一个简单的选择是使用 curl/awk/grep

【讨论】:

  • 感谢您的回答 Fliype。所以,我需要从我的编码部分获取 cart_id,然后将 PUT 发送到 cart_item。
  • 邮递员也可以这样做,但需要升级:blog.getpostman.com/2014/01/27/…
  • 这太棒了@Abhinav - 这绝对是 MAK 所追求的。邮递员的出色工作
猜你喜欢
  • 1970-01-01
  • 2015-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-09
  • 2019-09-07
  • 2021-12-27
相关资源
最近更新 更多