user2705444
user2705444

Reputation: 1

POST doesn't send data

I'm using Angularjs and spring mvc 3. I have in my controller class:

@Controller
@RequestMapping(value = "/elprocesses")
public class ELProcessController {
...
@RequestMapping(value = "/elprocess", method = RequestMethod.POST)
public @ResponseBody void save(@RequestBody final Entity01 entity01, 
    @RequestBody final Entity02 entity02
        ) {
    ...
}

ELProcessController.js :

$scope.saveForm = function(selectedname01) {
    $http.post('elprocesses/elprocess', {entity01:selectedname01, entity02:selectedname02});
...
}

it doesn't enter in my spring controller method, but when I send only one data with $http.post('elprocesses/elprocess', selectedname01); and changing my controller class with:

@RequestMapping(value = "/elprocess", method = RequestMethod.POST)
    public @ResponseBody void save(@RequestBody final Entity01 entity01)

this works fine,

What am I doing wrong to send entity01 and entity02?

Upvotes: 0

Views: 116

Answers (1)

DerekR
DerekR

Reputation: 3986

In your javascript, is selectedname02 defined anywhere?

If it is, then open up your network tab and you'll see whether or not it's sending data. The POST request has the header Content-Type: application/json by default though so make sure you're trying to get json data and not form encoded data or something. I'm not familiar with spring mvc at all so check their docs.

Upvotes: 1

Related Questions