赞
踩
第一种: 用$.param(xxx,true) 的方式进行序列化,后台用RequestParam接收
$.ajax({
type: "post",
url: url,
data: $.param({"courseId":courseId,"oldChooseClassIds":oldChooseClassIdArrs,"chooseClassIds":chooseClassIds},true),
dataType: "json",
async: false,
success: function (rs) {
if (rs.code == '200') {
oldChooseClassIdArrs = chooseClassIds;
isOk = true;
}else{
layer.alert(rs.msg);
}
}
});
后台:
@PostMapping("/saveOrUpdateCourseClassInfo")
public ResultEntry saveOrUpdateCourseClassInfo(@RequestParam(value = "courseId",required = false) String courseId,
@RequestParam List<Long> oldChooseClassIds,
@RequestParam List<Long> chooseClassIds){
jsSysCourseService.saveOrUpdateCourseClassInfo(oldChooseClassIds,chooseClassIds,courseId);
return ResultEntry.ok();
}
第二种:前端用传统方式序列化,后端用List<实体> 接收
$.ajax({
type: “post”,
url: url,
data: {“courseId”:courseId,“oldChooseClassIds”:oldChooseClassIdArrs,“chooseClassIds”:chooseClassIds},
dataType: “json”,
traditional : true,//用传统方式序列化数据
async: false,
success: function (rs) {
if (rs.code == ‘200’) {
oldChooseClassIdArrs = chooseClassIds;
isOk = true;
}else{
layer.alert(rs.msg);
}
}
});
后端:ao实体接收
@Setter
@Getter
public class ClassInfoAo {
private List oldChooseClassIds;
private List chooseClassIds;
private String courseId;
}
@PostMapping("/saveOrUpdateCourseClassInfo")
public ResultEntry saveOrUpdateCourseClassInfo(ClassInfoAo ao){
return ResultEntry.ok();
}
第三种:json接收 在做转化
@PostMapping("/saveOrUpdateCourseClassInfo")
public ResultEntry saveOrUpdateCourseClassInfo(String courseId,String oldChooseClassIds,String chooseClassIds){
JSONArray jsonArray = JSONObject.parseArray(oldChooseClassIds);
List<Long> list = JSONObject.parseArray(jsonArray.toJSONString(), Long.class);
return ResultEntry.ok();
$.ajax({
type: “post”,
url: url,
data: {“courseId”:courseId,“oldChooseClassIds”:JSON.stringify(oldChooseClassIdArrs),“chooseClassIds”:JSON.stringify(chooseClassIds)},
dataType: “json”,
async: false,
success: function (rs) {
if (rs.code == ‘200’) {
oldChooseClassIdArrs = chooseClassIds;
isOk = true;
}else{
layer.alert(rs.msg);
}
}
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。