如何从AngularJS发布到SpringMVC

时间:2015-12-13 23:47:22

标签: java angularjs spring-mvc

我在angularJS中有一个post方法,我将post方法发送到Spring MVC,但是Spring MVC没有返回新的ModelAndView。

  • AngularJS **

    var app = angular.module('userApp', []);
    
    app.controller('userController', [ "$scope", "$http",
    
        function($scope, $http) {
    
            $scope.user = {};
    
            $scope.addUser = function() {
                var response = $http.post('resultA', $scope.user)
                response.success(function(data, status, headers, config) {
                    $scope.message = data;
                });
                response.error(function(data, status, headers, config) {
                    alert("failure message: ");
                });
                alert("aa");
                $scope.name = '';
                $scope.employees = '';
                $scope.headoffice = '';
            };
    
        } ]);
    
  • SPRING MVC

    @RequestMapping(value = "/resultA", method = RequestMethod.POST)
    public @ResponseBody ModelAndView submitFormA(@RequestBody User user) {
    
        System.out.println(user.getUsername()+"");      
        return new ModelAndView("resultA");
    }
    

1 个答案:

答案 0 :(得分:0)

您的代码看起来很好。请确保存在resultA视图。或者,如果要返回String,请将方法返回类型更改为String