JAVA 传输post传输长字符、数据编码解码 反序列化字符串
JAVA 传输post传输长字符、数据编码解码
1.前段传输
这是传输的数组对象
2.后端接收格式已解码
JS代码:
$.ajax({
url:prefix+"/importModelTree",
data: {"modelId":modelId,"ruleId":ruleId,"model":JSON.stringify(array)},
type:"post",
dataType: "text",
success:function(res){
opt.success('模型信息导入成功');
},
});
JAVA后台代码
/**
* 导入模型信息
*/
@RequiresPermissions("bim:modelFamilyType:add")
@ResponseBody
@RequestMapping(value = "/importModelTree",method={RequestMethod.POST})
public String importModelTree(String modelId,String ruleId, String model){
model= URLDecoder.decode(model, "UTF-8");
//1、使用JSONObject
List<ImportModelFamily> modelInfo=(List<ImportModelFamily>) JSONArray.toList(JSONArray.fromObject(model), ImportModelFamily.class );
return "1";
}
实体类DTO(注意 一定要加注解@Data 否则会报错,序列化会调用set方法):
@Data
public class ImportModelFamily {
private String name;
private String code;
private ImportModelInstance component;
}
@Data
public class ImportModelInstance{
private String name;
private String[] componentId;
}