List<Teacher> teas = teaDao.findAllTea();
List<ClassRoom> rooms = roomDao.findAllRooms();
List<Class> classes = xiDao.findClassesByXiId(Integer.parseInt(xiId));
List<Text> texts = textDao.findXiByXiId(Integer.parseInt(xiId));
if(teas!=null&&rooms!=null&&classes!=null&&texts!=null){
JSONArray json = JSONArray.fromObject(classes);
JSONArray json1 = JSONArray.fromObject(rooms);
JSONArray json2 = JSONArray.fromObject(teas);
JSONArray json3 = JSONArray.fromObject(texts);
String jsonStr = json.toString();
String jsonStr1 = json1.toString();
String jsonStr2 = json2.toString();
String jsonStr3 = json3.toString();
response.setContentType("text/plain;charset=utf-8");
PrintWriter out = response.getWriter();
可以把这些json数组拼成字符串到前台解析:
out.print("{cla:"+jsonStr+",room:"+jsonStr1+",tea:"+jsonStr2+",text:"+jsonStr3+"}");
out.flush();
out.close();
前台解析:
var txt = xhr.responseText;
var stu=eval("("+txt+")");
for(var i=0;i<stu.cla.length;i++){
content+="<tr><td id='cla'>"+stu.cla[i].className+"</td><td id='room'>"+stu.room [i].roomNum+"</td><td id='tea'>"+stu.tea[i].teacherName+"</td><td id='textName'>"+stu.text[i].textName+"</td><td id='textDate'>"+stu.text[i].textDate+"</td></tr>";
}