• springmvc json数据


        @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; }
  • 相关阅读:
    资金平台交易明细扩展开发-DEP
    固定资产清理之源码研究
    后台事务开发之简单示例
    mbos之动态图表设计
    协同附件上传源代码研究
    EAS集锦
    扩展报表-JavaSet
    mogoDB 4.2.0安装部署及JAVA 客戶端应用
    kafka 2.12在linux下的安装部署及java客户端对接
    nginx: the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
  • 原文地址:https://www.cnblogs.com/wujixing/p/5799023.html
Copyright © 2020-2023  润新知