AngularJS:没有从用户界面调用慢速java方法

时间:2014-04-20 04:22:33

标签: java javascript spring angularjs rest

我的设置:

我想调用一个从UI接受字符串并返回JSON字符串的java方法。此方法需要5秒以上的时间来计算并返回JSON字符串。当我使用UI作为参数输入时,甚至没有调用此方法:我确认这是因为某些文件是在本地创建的,但尚未创建。

Setter方法:

public void setBrand(String brand) {
this.brand  = AmazonReview.getAmazonReview(this.brand);
  }

缓慢的方法:

public static String getAmazonReview(String s){
...;
Process p1 = Runtime.getRuntime().exec("./something.pl com " + id);
...;
JSONObject obj = new JSONObject();
obj.put("product1", l1);
return obj.toJSONString();
}

Getter方法:

public String getBrand() {
    return brand;
  }

用户界面代码

angular.module("sprang", ["sprang.services"]).
    config(function ($routeProvider) {
        $routeProvider
            .when('/brands', {templateUrl: '/views/brands/list.html', controller: BrandListController})
            .when('/brands/:brandId', {templateUrl: '/views/brands/detail.html', controller: BrandDetailController});
    });

function BrandListController($scope, Brand) {
        $scope.brands = Brand.query();
        $scope.deleteBrand = function(brand) {
            brand.$delete(function() {
                $scope.brands.splice($scope.brands.indexOf(brand),1);
                toastr.success("Deleted");
            });
        }
    }

function BrandDetailController($scope, $routeParams, $location, Brand) {
        var brandId = $routeParams.brandId;
        if (brandId === 'new') {
            $scope.brand = new Brand();
        } else {
            $scope.brand = Brand.get({brandId: brandId});
        }
        $scope.save = function () {
            if ($scope.brand.isNew()) {
                $scope.brand.$save(function (brand, headers) {
                    toastr.success("Created");
                    var location = headers('Location');
                    var id = location.substring(location.lastIndexOf('/') + 1);
                    $location.path('/brands/' + id);
                });
            } else {
                $scope.brand.$update(function() {
                    toastr.success("Updated");
                });
            }
        };
    }

问题:

如果我只用return "Hello";替换方法代码,我的UI就会显示Hello。 我的项目是使用带有Spring的AngularJS设置的,它的端到端工作正常。 我试图让方法在本地保存json,因此UI被称为必须显示输出,仍然没有调用方法。 我该怎么办?提前谢谢。

简单来说,当我在eclipse中调用我的慢速java方法时,我得到了预期的JSON,但是当我使用UI(AngularJS)执行相同操作时,该方法未被调用。

0 个答案:

没有答案