码迷,mamicode.com
首页 > 编程语言 > 详细

springmvc json数据

时间:2016-08-23 14:36:15      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

    @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; }

 

springmvc json数据

标签:

原文地址:http://www.cnblogs.com/wujixing/p/5799023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!