的
@RequestMapping("/getAllEdu") @ResponseBody public void getAllEdu(HttpServletRequest request,HttpServletResponse response){ List<Education> eduList = eduService.findAll(); //request.setAttribute("edus", edus); //response.setCharacterEncoding("UTF-8"); //response.setContentType("text/html"); response.reset(); response.setCharacterEncoding("UTF-8"); //response.setContentType("application/json;charset=utf-8"); response.setContentType("text/html"); JSONArray members = new JSONArray(); PrintWriter out= null; try { out= response.getWriter(); for(Education e:eduList){ JSONObject member = new JSONObject(); member.put("eduid", e.getId()); member.put("edutitle", e.getEdutitle()); member.put("objective", e.getObjective()); member.put("contents", e.getContents()); member.put("schedule", e.getSchedule()); member.put("duration", e.getDuration()); member.put("trainerName", e.getTrainerName()); member.put("department", e.getDepartment()); member.put("trainee", e.getTrainee()); member.put("remarks", e.getRemarks()); members.add(member); } out.write(members.toString()); } catch (Exception e) { System.out.println(e.getMessage()); } //out.flush(); out.close(); //return "/eduController/eduManager"; } //第二种方式
@RequestMapping(value="/getAllEdu", )
@ResponseBody
public List<Education> getAllEdu(HttpServletRequest request,HttpServletResponse response){ List<Education> eduList = eduService.findAll(); return eduList; }