使用ajax传参有三种格式:字符串,xml,json
可以使用json来传递实体对象或传递实体对象的集合,方法如下:
传实体:
前台
var entity = {"id":selectedId,"meterCode":meterCode,"meterNumber":meterNumber,"employeeCode":employeeCode,"employeeName":employeeName,"operateResource":operateResource,"treatmentMeasures":treatmentMeasures};
params: {
entityString: JSON.stringify(entity)
},
后台接收
public ResponseResult closingWorkOder( @RequestParam String entityString) {
SecurityEntity entity = JSONArray.toJavaObject((JSONObject) JSONArray.parse(entityString), SecurityEntity.class);
}
传实体集合:
前台:
params: {
itemsEntities: JSON.stringify(downData)
},
这里的参数值类似于:
"[{"chargeName":"111","price":"11","count":"111","total":1221},{"chargeName":"111","price":"11","count":"111","total":1221}]"这种json串;
后台接收
public ResponseResult closingWorkOder(@RequestParam String itemsEntities) {
List<SecurityTaskItemsEntity> itemsEntityList = JSONArray.parseArray(itemsEntities, SecurityTaskItemsEntity.class);
}