在from表单提交的时候有的数据有一对多关系想提交一次就包含 多的一方的数据,不知道如何传一个list对象

下面介绍一种参数传递list数据的方法,使用json传递数据,然后在后台用jsonobject把json字符串转换成对象处理。

jsp页面:

name:
routePoiListJson

后台处理:

//使用jsonobjec把json字符串转换成对象

JSONObject jsonObj = JSONObject.fromObject(routePoiJson);
JSONArray jsonArray = jsonObj.getJSONArray("routePois");
List routePoiList = new ArrayList();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject poiJson = (JSONObject)jsonArray.get(i);
RoutePoi routePoi =(RoutePoi)JSONObject.toBean(poiJson, RoutePoi.class);
if(poiJson != null)
routePoiList.add(routePoi);
}