【发布时间】:2017-05-01 01:29:22
【问题描述】:
我是 AngularJS 和 spring boot 的新手,我需要通过 post 方法中的空对象传递表单提交数据,这是 HTML 文件:
<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>
这是我的 app.js 代码
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");
});
};
});
这是我的休息控制器类
@RestController
public class CatalogueController {
@Autowired
private IProduitRepository prouitRepository ;
@RequestMapping(value = "/save",method = RequestMethod.POST)
public Produit SaveProduit(@RequestBody Produit p){
return prouitRepository.save(p);
}
}
【问题讨论】:
-
有什么问题?
-
post方法中传入一个空对象
标签: java angularjs object post spring-boot