简体   繁体   中英

POST method and return JSON Object

In my main class spring boot, I want to verify the information which are in the method parameters and do some logic to return JSON Object with attribute "code" which contains a value "0" But I'm getting the 400 bad request in postman.

在此处输入图像描述

在此处输入图像描述

You can not use @RequestBody twice at same request as there is only one. I guess you have an object called user with the fieldes as your json. You should change the method signiture to validateItems(@RequestBody User user) And your json to user:{... Fieldes and values}

Create a Model class with parameters and pass the Model through the @RequestBody

Controller

@PostMapping(value = "/signin")
@ResponseBody
public String something(@RequestBody Model myModel) 
{
    return "";
}

Model

class Model {

  private String param1;
  private String param2;

  Model() {}

  Model(String param1, String param2) {
    this.param1 = param1;
    this.param2 = param2;
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM