【问题标题】:How to insert using rest API created using SPRING BOOT DATA REST如何使用使用 SPRING BOOT DATA REST 创建的 REST API 插入
【发布时间】:2018-08-11 16:38:42
【问题描述】:

嗨,我是个菜鸟,我正在尝试学习如何在 Spring Boot 中使用它。

我使用 Spring Boot Data Rest 生成了一个 Rest 服务,由于我没有所有关于 rest 的基础知识,我想知道如何使用 POST 插入我的数据库,因为我知道我有一个如下所示的答案

http://localhost:8080/mNG_USERs

{
"_embedded": {
    "mNG_USERs": [
        {
            "us_cextusr": "1234e",
            "us_nomusr": "test",
            "us_prnusr": "test",
            "us_pwdusr": "123456",
            "us_datdeb": "2018-03-03",
            "us_datfin": "2018-03-03",
            "us_nbrerr": 1,
            "us_datcre": "2018-03-03",
            "us_datmaj": "2018-03-03",
            "us_etatusr": null,
            "us_typusr": null,
            "us_lastprg": null,
            "us_nivacc": null,
            "_links": {
                "self": {
                    "href": "http://localhost:8080/mNG_USERs/1"
                },
                "mNG_USER": {
                    "href": "http://localhost:8080/mNG_USERs/1"
                },
                "us_langue": {
                    "href": "http://localhost:8080/mNG_USERs/1/us_langue"
                },
                "us_lastuser": {
                    "href": "http://localhost:8080/mNG_USERs/1/us_lastuser"
                }
            }
        }
    ]
},
"_links": {
    "self": {
        "href": "http://localhost:8080/mNG_USERs{?page,size,sort}",
        "templated": true
    },
    "profile": {
        "href": "http://localhost:8080/profile/mNG_USERs"
    }
},
"page": {
    "size": 20,
    "totalElements": 1,
    "totalPages": 1,
    "number": 0
}
}

我正在使用邮递员生成请求我知道我应该使用POST请求但我不知道如何写它

【问题讨论】:

  • 在你去尝试做这样的事情之前,你应该看看 REST 基础知识。您可以获得显示的代码,但除非您了解所显示的是什么,否则它根本不会使您受益。
  • spring.io/understanding/REST 请问我能从中得到什么

标签: java spring rest spring-boot


【解决方案1】:

经过一些工作和研究

首先在 postman 下使用 curl 很简单,我们必须在我的案例帖子中选择合适的方法来创建(因为我将使用 put 来更新),其次 Spring Boot Data Rest 生成的 API 有很好的文档记录,你可以发现它通过发布到您的 RestApi 主机。

为了构建我的帖子,我使用了 Post : http://localhost:8080/mNG_USERs 并且在邮递员中有一个正文部分,我选择了原始和 JSON 格式

{
  "us_cextusr" : "123158E",
  "us_nomusr" : "test",
  "us_prnusr" : "loli",
  "us_pwdusr" : "123456",
  "us_datdeb" : "2018-03-03",
  "us_datfin" : "2018-03-03",
  "us_nbrerr" : 1,
  "us_datcre" : "2018-03-03",
  "us_datmaj" : "2018-03-03",
  "us_etatusr" : null,
  "us_typusr" : null,
  "us_lastprg" : null,
  "us_nivacc" : null  
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多