简体   繁体   English

如何使用邮递员休息客户端将自定义dto作为休息api输入传递

[英]how to pass custom dto as rest api input using postman rest client

Here is my code ,I'm trying to pass the user details as a json input but I'm not able to receive the data in my rest api method. 这是我的代码,我试图将用户详细信息作为json输入传递,但是我无法通过rest api方法接收数据。 I"m getting all values as null, 我将所有值都设为null,

this is my json request 这是我的json请求

{
    "userId" : "12345",
    "username" : "arun.ammasai",
    "createdBy" : "-2",
    "updatedBy" : "-2",
    "statusCd" : "New",
    "createdDate" : "2019-03-03",
    "updatedDate" : "2019-03-03"
}

==================================================================== ================================================== ==================

@RequestMapping(value = "/registerUser", method = RequestMethod.POST, consumes = { "application/JSON", "application/XML" })
private String registerUser(User user) {
    System.out.println(user.toString());
    return "User Created";
}

==================================================================== ================================================== ==================

here is the response in Postman Client 这是邮递员客户端中的响应

Unexpected 'U' 意外的“ U”

Update your method signature with @RequestBody annotation. 使用@RequestBody批注更新您的方法签名。 It will automatically deserialize your json into java entity. 它将自动将json反序列化为Java实体。 Be carefull, names in json should be the same as parameters in User object and User object should have getters and setters. 请注意,json中的名称应与User对象中的参数相同,并且User对象应具有getter和setter。 So your method should look like 所以你的方法应该像

    @RequestMapping(value = "/registerUser", method = RequestMethod.POST, consumes = { "application/JSON", "application/XML" })
        private String registerUser(@RequestBody User user) {
            System.out.println(user.toString()); //What is the reason of doing toString of java Object? 
            //better to do System.out.println(user.getUsername())
            return "User Created";
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用邮递员休息客户端发送对象以调用REST服务 - how to send object using postman rest client to call REST service 如何使用 Rest 将多个文件作为输入传递给 api - How to pass multiple files as a input to an api using Rest Assured 如何使用邮递员将用户登录详细信息传递给Spring Boot Rest API - How to pass user login details to Spring Boot Rest API using postman 调试不适用于其他方法使用邮递员其他客户端的PUT - debug not working for rest method PUT using postman rest client 如何使用邮递员测试提供 .zip 文件的 REST API? - How to test REST API which serve a .zip file using postman? 如何使用邮递员调用REST API进行Azure文件存储? - How to call REST API for azure file storage using postman? rest api - 如何在rest api调用中发送邮递员的身体参数 - rest api - how to send body parameters of postman in rest api call 如何将输入参数传递给来自Rest Client的Jboss BRMS规则 - How to pass input parameters to a Jboss BRMS Rule from Rest Client 如何在Spring Restful Web Services中使用Rest Client传递输入参数 - How to pass input parameters using rest client in spring restful web services 如何在 Z03D476861AFD3841110F2CB80CCFA8 中请求 Rest API eclipse 服务? - How to request Rest API eclipse service in postman?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM