传递三个字符串和一个数组
js中代码
//拼装json数据
var surveyResponse = {};
var questionIdList2= new Array();
questionIdList2[0] = 1;
questionIdList2[1] = 2;
questionIdList2[3] = 3;
surveyResponse.surveyTitle = "测试标题";
surveyResponse.surveyIntroduction = "测试标题";
surveyResponse.surveyAuthor = "测试作者";
surveyResponse.questionIdList = questionIdList2;
$.ajax({
type : 'POST',
url: '/admin/survey/save2',
contentType : "application/json;charset=utf-8" ,
dataType:"json",
data : JSON.stringify(surveyResponse),
success : function(data) {
}
});
controller
@RequestMapping("/save2")
@ResponseBody
public String putMessage(@RequestBody SurveyResponse surveyResponse){
System.out.println(surveyResponse.getSurveyAuthor());
System.out.println(surveyResponse.getSurveyIntroduction());
System.out.println(surveyResponse.getSurveyTitle());
final List<String> questionIdList = surveyResponse.getQuestionIdList();
for (int i = 0; i < questionIdList.size(); i++) {
String s = questionIdList.get(i);
if (s!=null && s!= ""){
System.out.println("获取到的list为:"+s);
}
}
return "success";
}
解析json的实体类
@Data
public class SurveyResponse {
private String surveyTitle;
private String surveyAuthor;
private String surveyIntroduction;
private List<String> questionIdList;
}