Java - spring controller - Angularjs form submission
Problem is with "@RequestBody OfferForm data" when i submit form i get error "404 bad request" but when i replace OfferForm bean with String object it works fine and display form data in json format.
any help appreciated.
Following is my angularjs function code
$scope.submitOffer = function() {
alert('submitOffer')
$http({method: 'POST', url: '/offer/submitOffer', data: $scope.formData}).
success(function(data, status, headers, config) {
$scope.successMsg = data;
}).
error(function(data, status, headers, config) {
if(status == 400) {
$scope.errMessages = data;
} else {
alert('Unexpected server error.');
}
});
};
Following is my controller code
@RequestMapping(value="offer")
public class OfferController{
@RequestMapping(value = "/submitOffer", method = RequestMethod.POST)
@ResponseBody public ResponseEntity<?> postForm(@RequestBody OfferForm data) {
System.out.println(data);
return new ResponseEntity<String>("Offer Created", HttpStatus.OK);
}
}
Following is my java bean
public class OfferForm {
private String offerType;
private String offerTitle;
public String getOfferType() {
return offerType;
}
public void setOfferType(String offerType) {
this.offerType = offerType;
}
public String getOfferTitle() {
return offerTitle;
}
public void setOfferTitle(String offerTitle) {
this.offerTitle = offerTitle;
}
}
$scope.formData? It should be an object with at most two properties of type string:offerTypeandofferTitle. I think you have more properties than expected, thus the bad request