I'm new to AngularJS and spring boot I need to submit data via form a null object pass in the post method this is HTML file:
<body ng-app="MyCat" ng-controller="CatController" >
<form>
<label>des:</label>
<input type="text" ng-model="m.des" name="des">
<label>prix:</label>
<input type="text" ng-model="m.prix" name="prix" >
<input ng-click="submit()" type="button" value="ajouter"/>
</br></br>
</form>
</body>
this is my app.js code
var MyCat = angular.module('MyCat',[]);
MyCat.controller('CatController',function($scope,$http){
$scope.produit=[];
$scope.motCle=null;
$scope.pageCourante=0;
$scope.m={};
$scope.submit = function() {
$http.post("/save",$scope.m)
.success(function(data) {
alert("Task added");
});
};
});
this is my rest controller class
@RestController
public class CatalogueController {
@Autowired
private IProduitRepository prouitRepository ;
@RequestMapping(value = "/save",method = RequestMethod.POST)
public Produit SaveProduit(@RequestBody Produit p){
return prouitRepository.save(p);
}
}
you can't save a null object this
prouitRepository.save(p)Throws: IllegalArgumentException - in case the given entity is null.