Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 数据通过angular js发送到spring控制器并通过hibernate插入表时不工作_Angularjs_Spring Mvc - Fatal编程技术网

Angularjs 数据通过angular js发送到spring控制器并通过hibernate插入表时不工作

Angularjs 数据通过angular js发送到spring控制器并通过hibernate插入表时不工作,angularjs,spring-mvc,Angularjs,Spring Mvc,这里我必须通过$http.get将数据发送到spring控制器,但问题是响应未定义异常发生 这是我的angularJS代码 var app=angular.module('exitApp',['ui.router']);

这里我必须通过$http.get将数据发送到spring控制器,但问题是响应未定义异常发生

这是我的angularJS代码

      var app=angular.module('exitApp',['ui.router']);                                                                                                                                                   config(function($stateProvider,$urlRouterProvider){
       //$urlRouterProvider.otherwise('/resignation');
       $stateProvider
      .state('exit',{
       url:'/exit',
      templateUrl:'resources/js/exit.html',
      controller:'exitCtrl'
      });
      });

     app.controller('exitCtrl', ['$scope','$http',function($scope,$http) {
     /*$scope.name='';
     $scope.department='';
     $scope.myDate='';
     $scope.designation='';
     $scope.location='';
     $scope.opinion='';
     $scope.performance='';
     $scope.signs='';
     $scope.persuaded='';
     $scope.role='';*/

      $scope.headerText = 'Exit Employee Details..';
    $scope.data=[];

     $scope.submitForm=function(user){
    /*$scope.data.push(user);*/

     var exitdata={
            "name": $scope.name,
            "department":$scope.department,
            "mydate":$scope.myDate,
            "designation":$scope.designation,
            "location":$scope.location,
            "releaving":$scope.releaving,
            "opininon":$scope.opinion,
            "performance":$scope.performance,
            "signs":$scope.signs,
            "persuaded":$scope.persuaded,
            "role":$scope.role
                };

        var exitresponse=$http.get('/hrms/?exit=' +exitdata);
        exitresponse.success(function(user,status,headers,config){
            $scope.data.push(user);

            exitresponse.success(function(){
                alert("Approved! "+ exitdata);
                console.log("msg sent");
            })
        });

          response.error(function(user,status,headers,config){
          alert("Exception details:" + JSON.stringify({user: user}));
          });

          $scope.data.push(user);

          $scope.data=[];

       }
    }]);
这是我的springController代码,我正在尝试响应$hhtp.get-get-data-to-spring-by/exit url:

       @RequestMapping(value="/exit",method=RequestMethod.GET)
       @ResponseStatus(value = HttpStatus.OK)
       @ResponseBody 
      public String PostService(@RequestParam(value="name") String name) {
      System.out.println(name);

     return "exit";

您试图用错误的
http
方法
GET
实现您的目标,请改用
POST
。当您想要发送整个对象时,我们使用POST方法GET只支持附加到请求的字符串,而不支持整个对象

另外,您正尝试使用
.success
作为
$http
而不是使用
。然后,Angular as
建议使用
。success
不推荐使用

在JS中进行如下更改

     app.controller('exitCtrl', ['$scope','$http',function($scope,$http) {


          $scope.headerText = 'Exit Employee Details..';
        $scope.data=[];

         $scope.submitForm=function(user){
        /*$scope.data.push(user);*/

         var exitdata={
                "name": $scope.name,
                "department":$scope.department,
                "mydate":$scope.myDate,
                "designation":$scope.designation,
                "location":$scope.location,
                "releaving":$scope.releaving,
                "opininon":$scope.opinion,
                "performance":$scope.performance,
                "signs":$scope.signs,
                "persuaded":$scope.persuaded,
                "role":$scope.role
                    };

        $http.post('/hrms/exit', exitdata).then(function(res) {
                  console.log(res);
                  var user = res.data;
                  $scope.data.push(user);

               }).error(function(res) {

               alert("Exception details:" + res.error);
               });

             $scope.data.push(user);

               $scope.data = [];
        }]);
在控制器中,从GET更改为POST

//NOTE: ExitData  is model class which you are sending...
@RequestMapping(value="/exit",method=RequestMethod.POST,headers="Accept=application/json") 

   @ResponseBody 
  public String PostService(@RequestBody ExitData exitdata) {
  System.out.println(exitdata.getName());

 return "exit";

您试图用错误的
http
方法
GET
实现您的目标,请改用
POST
。当您想要发送整个对象时,我们使用POST方法GET只支持附加到请求的字符串,而不支持整个对象

另外,您正尝试使用
.success
作为
$http
而不是使用
。然后,Angular as
建议使用
。success
不推荐使用

在JS中进行如下更改

     app.controller('exitCtrl', ['$scope','$http',function($scope,$http) {


          $scope.headerText = 'Exit Employee Details..';
        $scope.data=[];

         $scope.submitForm=function(user){
        /*$scope.data.push(user);*/

         var exitdata={
                "name": $scope.name,
                "department":$scope.department,
                "mydate":$scope.myDate,
                "designation":$scope.designation,
                "location":$scope.location,
                "releaving":$scope.releaving,
                "opininon":$scope.opinion,
                "performance":$scope.performance,
                "signs":$scope.signs,
                "persuaded":$scope.persuaded,
                "role":$scope.role
                    };

        $http.post('/hrms/exit', exitdata).then(function(res) {
                  console.log(res);
                  var user = res.data;
                  $scope.data.push(user);

               }).error(function(res) {

               alert("Exception details:" + res.error);
               });

             $scope.data.push(user);

               $scope.data = [];
        }]);
在控制器中,从GET更改为POST

//NOTE: ExitData  is model class which you are sending...
@RequestMapping(value="/exit",method=RequestMethod.POST,headers="Accept=application/json") 

   @ResponseBody 
  public String PostService(@RequestBody ExitData exitdata) {
  System.out.println(exitdata.getName());

 return "exit";

解决方案有用吗?解决方案有用吗?