Wie teste ich POST spring mvc?
Mein Problem ist, wie man das nennt. ich könnte
MyObject o = new MyObject();
myController.save(o, "value");
das möchte ich aber nicht tun. Ich möchte, dass sich das MyObject im Post-Body der Anfrage befindet. Wie geht das?
@Requestmapping(value="/save/{value}", method=RequestMethod.POST)
public void post(@Valid MyObject o, @PathVariable String value{
objectService.save(o);
}
Um ganz klar zu sein, ich spreche über Unit-Tests.
Bearbeiten:
@RequestMapping(value = "/", method = RequestMethod.POST)
public View postUser(ModelMap data, @Valid Profile profile, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return dummyDataView;
}
data.put(DummyDataView.DATA_TO_SEND, "users/user-1.json");
profileService.save(profile);
return dummyDataView;
}