Spring从客户端接收数据

时间:2013-12-15 18:52:01

标签: spring model-view-controller

晚上好!

 public class Order  {
   private int idOrder;
   private Basket basket;
// getter and setter
 }

public class AnonymousOrder  {
  private String name;
  private String telephone;
// getter and setter
}

public class UserOrder  {
  private User user;
// getter and setter
}


public class OrdersForm {
  private List< ? extends  Order> orders;    
 // getter and setter  
}

@RequestMapping(value="/showOrders")
 public String showOrders(Model model){
    List<? extends Order> orders= adminManager.searchAllOrders();
    OrdersShowForm ordersForm = new OrdersShowForm();
    ordersForm.setOrders(orders);
    model.addAttribute("ordersForm", ordersForm);
    return "showOrders";
}


@RequestMapping(value="/showOrders", method = RequestMethod.POST)
public String showOrdersPOST(@ModelAttribute("ordersForm") OrdersShowForm ordersForm){

    System.out.print(ordersForm);
    return "showOrders";

}

 <form:form modelAttribute="ordersForm">   
    <table class="features-table" border="1">
              <c:forEach items="${ordersForm.orders}" var="order" varStatus="status">
            <tr>
                <c:if test="${order['class'].simpleName != 'UserOrder'}">
                    <td>
                        <input name="orders[${status.index}].name" value="${order.name}"/>

                    </td>
                </c:if>
        </c:forEach>
   </table>

问题:我传递了第二种类型的数据:UserOrder和AnonymousOrder,但是当我尝试在服务器上获取它们时,请来数据类型Order。 问题:如何在不改变实际类型的情况下将数据传输到服务器?

P.S。抱歉我的英文)

0 个答案:

没有答案