0

I have an API for front side,I use postman to send a single number 8.

I want to send like this way in Postman

@RequestMapping(value="/query",method=RequestMethod.POST)
@ResponseBody
public String query(@RequestBody Integer number ){  

    return dao.query(number);
}

but now the front side say they can not send a single word with no key-value in json,I don't want to create an object just use that once to binding, how can I do this?

MAX
  • 53
  • 9

2 Answers2

1

Have a look at requestparam

@RequestMapping(value = "/query", method=RequestMethod.POST)
@ResponseBody
public String query(@RequestParam("number") Integer number){
  return dao.query(number);
}

The request should be like /query?number=8

Alien
  • 15,141
  • 6
  • 37
  • 57
  • @detail0805 that is not possible,,,when you say json it means key value pair is must. – Alien Oct 09 '18 at 06:57
  • ok,I check it for js api,it will be possible to send single parameter ,but its not officially ...so you are the right . – MAX Oct 09 '18 at 06:59
0

Change Integer to String and you are good to go without doing anything else. Hope this helps you.

@RequestMapping(value="/query",method=RequestMethod.POST)
 @ResponseBody
 public String query(@RequestBody String number ){  

      return dao.query(number);
 }
Usman Ali
  • 58
  • 4