【问题标题】:how to send object using postman rest client to call REST service so that it will hit the below given method with proper method parameters?如何使用邮递员休息客户端发送对象以调用 REST 服务,以便它使用正确的方法参数访问下面给定的方法?
【发布时间】:2020-01-01 13:31:59
【问题描述】:

我想从邮递员那里调用一个休息后的方法。但是我无法正确设置邮递员方法的输入参数。

注意:请不要将其标记为重复,因为此剂量在 Stackoverflow 中已有答案。

其余API代码如下:

@RequestMapping(value = "/city/village/home", method = RequestMethod.POST)
    @ResponseBody
    public String updateHome(@ModelAttribute final HomeAddress homeAddress,
            final HttpServletRequest request) {

            //// some code ///// 

            }



This is the HomeAddress class

public class HomeAddress{

  public String name;
  public int id;
  public List<String> membersName;


  getters.....
  setters....

  }

请告诉我如何从 Postman 发送请求?

【问题讨论】:

    标签: java rest api spring-mvc postman


    【解决方案1】:

    如果您默认使用 Spring,您的应用程序将在 localhost:8080 上运行 -> 那么您可以使用您的值 /city/village/home -> localhost:8080/city/village/home。 您可以查看 Spring Boot Controller 的示例 - https://adityasridhar.com/posts/how-to-create-simple-rest-apis-with-springboot

    我不确定你是否在课堂上使用了@Controller 注释等等...... 您可以在此处查看如何使用 Postman-> https://adityasridhar.com/posts/how-to-create-simple-rest-apis-with-springboot

    你应该使用 Json 格式 - 你可以在这里验证它:https://jsonformatter.curiousconcept.com/

    {
      "name": "NAme",
      "id": 5,
      "membersName": [
         "firstName",
        "secondName"
      ]
    }
    

    【讨论】:

    • 我的疑问是如何从邮递员那里调用它?我应该在请求正文中使用这个 Json 吗?
    • 是的,您需要将 json 放在“Body”扇区中。在“标题”部分,您应该输入 Key -> Content-Type and Value -> application/json
    猜你喜欢
    • 2017-09-06
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多