java 参数传list多个对象数据的方法

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

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

jsp页面:

<form action="${pageContext.request.contextPath}/route/insert" method="POST">
		name:<input id="" name="name" value=""><br>		
		
		routePoiListJson<input id="" name="routePois" value='{"routePois":[{"id":1,"routeId":1,"orderNum":1,"poiId":1,"name":"abc","lon":1,"lat":1,"type":"1","distance":2,"timeSchedule":1,"arrivePlanTime":1381334400000,"timeStay":0,"deleteFlag":"0","createUserId":11,"createTime":1386751247100,"updateUserId":11,"updateTime":1386751247100}]}'><br>
		<input type="submit">
	</form>

后台处理:

//使用jsonobjec把json字符串转换成对象
JSONObject jsonObj = JSONObject.fromObject(routePoiJson);
JSONArray jsonArray =  jsonObj.getJSONArray("routePois");
List<RoutePoi> routePoiList =  new ArrayList<RoutePoi>();
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);
}
来源:本站//作者:admin/更新时间:2013-12-26
相关文章
评论:
验证码:
匿名评论:

最新文章

文章排行