【问题标题】:spring boot and angular js using Rest service and post methode to send an objectspring boot 和 angular js 使用 Rest 服务和 post 方法发送对象
【发布时间】: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


【解决方案1】:

你不能保存一个空对象这个prouitRepository.save(p) 抛出: IllegalArgumentException - 如果给定实体为空。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-26
    • 1970-01-01
    • 2017-06-19
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 2017-09-10
    相关资源
    最近更新 更多