springmvc json数据
2016-08-23 13:45
260 查看
的
@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格式数据的接收和发送(未解决中文乱码问题)
- SpringMVC从Controller中响应json数据
- springMvc如何和前端页面交互,传输json数据
- 用springMVC构建restful程序,接收以及返回json数据格式
- 解决SpringMVC返回Json数据格式不严谨报异常的问题(草稿未完成)
- SpringMVC对json数据的处理
- springmvc 返回json数据给移动端,配置及代码示例
- springMVC框架下JQuery传递并解析Json数据
- SpringMVC返回json格式的数据
- SpringMVC 中向后台传入json数据的问题
- SpringMVC之json数据传递
- SpringMVC返回JSON数据时日期格式化问题
- SpringMVC从Controller中响应json数据
- springMVC框架下JQuery传递并解析Json数据
- springMVC框架下JQuery传递并解析Json数据
- springMVC_json格式数据的接收和发送(未解决中文乱码问题)
- SpringMVC从Control中响应json数据
- SSH框架,AjaxJson显示数据,项目框架搭建;注意action跳转不用叹号,springMVC和springAnnotation要修改spring配置文件
- 用springmvc作接口时返回json数据中文乱码
- SpringMVC Android 发送JSON数据