如何将数据从AngularJS表单传递给struts 2动作类?

时间:2015-10-15 04:27:59

标签: angularjs spring

这里我正在开发购物车。这是我的AngularJS控制器。此方法用于将数据发送到操作 使用$ http.post方法的类

 angular.module("sportsStore")
.constant("dataUrl", "angularAction")
.constant("orderUrl", "angularSaveAction")
.controller("sportsStoreCtrl", function ($scope, $http, $location,
                                         dataUrl, orderUrl, cart) {
 enter code here`$scope.data = {
    };
    $scope.sendOrder = function (shippingDetails) {
        var order = angular.copy(shippingDetails);    
        order.products = cart.getProducts();
        console.log(order);--------------(1)
        $http.post(orderUrl, order)
            .success(function (data) {
                //$scope.items=data;
                $scope.data.orderId = data.id;
                cart.getProducts().length = 0;
                console.log(data);---------------(2)
            })
            .error(function (error) {
                $scope.data.orderError = error;
            }).finally(function () {
                $location.path("/complete");
            });
    }});

使用(1)console.log我确认所有表单数据和购物车详细信息stoed array.But(2)console log is Null 这是我的Action类

   package com.ai.action;
   import com.ai.model.PersonData;
   import com.ai.model.Product;
   import com.ai.model.ProductOrder;
   import com.ai.model.Village;
   import com.ai.service.PersonService;
   import com.opensymphony.xwork2.Action;
   import com.opensymphony.xwork2.ActionContext;
   import com.opensymphony.xwork2.ActionSupport;

   import com.opensymphony.xwork2.ModelDriven;
   import org.apache.struts2.dispatcher.mapper.ActionMapping;
   import org.slf4j.Logger;

  public class OrderAction extends 
    ActionSupport implements ModelDriven<ProductOrder> {--------------(1)

  private Map session = ActionContext.getContext().getSession();
  private Logger logger = LoggerFactory.getLogger(AngularAction.class);

  private List<ProductOrder> order;-------------(2)

  private ProductOrder productOrder;

  @Autowired
  private PersonService  personService;

public String execute()

{
    getOrder();
    logger.info("this method ic" ,order);
    //personService.save(personService);----------(3)
    return SUCCESS;
}

public List<ProductOrder> getOrder() {
    return order;
}

public void setOrder(List<ProductOrder> order) {
    this.order = order;
}

@Override
public ProductOrder getModel() {
    return productOrder;
}

 }

我如何获取表单数据  我可以用吗 ModleDriven(1)或 列表数组(2)或任何方法。我希望使用hibernate(3)将此表单数据保存在mysql数据库中。请帮助我.... 我如何获得表单数据  我可以用吗 ModleDriven(1)或 列表数组(2)或任何方法。我希望使用hibernate(3)将此表单数据保存在mysql数据库中。请帮助我......

0 个答案:

没有答案