0

Can i send http post with also RequestBody and RequestParam?? I want to send some data in that way: data - is requestbody and params is RequestParam.

var Indata = {'cityName': object.cityName };
$http({method: 'POST', url: OBJECT_REST, data: object, params: Indata}).
                then(function(response) {
                    alert("saved");
                  $rootScope.$broadcast('refreshUserGrid');
                  $rootScope.$broadcast('clearForm');
                }, function(response) {
                  console.log(response.status);
              });

and in PostMapping controller i want to get this data:

@PostMapping(consumes = MediaType.APPLICATION_JSON)
    public ResponseEntity<?> saveSportObject(@RequestBody SportObject object, @RequestParam String cityName) {

It's possible to using requestBody with RequestParam in similar way to this one?

smok010
  • 11
  • 3
  • I don't think you can. [Check out this other post on the subject](https://stackoverflow.com/questions/19468572/spring-mvc-why-not-able-to-use-requestbody-and-requestparam-together). – Eli Huntington Nov 09 '17 at 23:33
  • Because it is weird for RESTful service design with POST method to receive request parameters and body in the same time. Even you can do this, I don't think that is a good interface. – LHCHIN Nov 10 '17 at 02:45
  • Can't you just include the params in URL `url:OBJECT_REST+'?cityName='+object.cityName` – StanislavL Nov 10 '17 at 06:50

0 Answers0