echarts实例,前后台数据调用

第一步:testEcharts.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"";
%>



   
   
   
   
   
    ECharts · Example

   

   
   
   
   
   
   

   
   
   

   
   


   
   


     


   


       

           
           

               

                555tytytuyu
               

              
    
               
               
               
               
               
               
               

                   
                    切换主题
                   

                   
               


           

       

       
       

   


   
   
    <%--
   
    --%>
   


 

第二步:调用后台此方法

 
 /**
  * testecharts
  * @throws IOException
  * @throws Exception
  */
 public String testEcharts() throws IOException {
  List queryList = userService.query(user);
  //PrintWriter writer=null;
  //for (User user : queryList) {
   //user.setName(user.getName());
   //String name = user.getName();
   //int num = user.getNum();
   //user.setName(user.get)
   //queryList.add(user);
  //}
 /* JSONArray json=null;
  try {
  //调用jsonAray.fromobject方法把array中的对象转换为json格式的数组
   json = JSONArray.fromObject(queryList);//得到的是json数据的数组
  String jsonString = json.toString();
  System.err.println("jsonString:"+jsonString);
  // 返回给前台页面
  
 
   writer = response().getWriter();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  writer.println(json);
  writer.flush();
  writer.close();
  
  return null;
  
 }
 */
  // System.err.println(userList);
  Gson gson = new Gson();
  /**
   * //[{"id":1,"loginName":"admin","password":
   * "21232f297a57a5a743894a0e4a801fc3",
   * "name":"\u8d85\u7ea7\u7ba1\u7406\u5458","beginTime":{},"endTime":{}},
   * {"id":2,"loginName":"shen","password":
   * "81dc9bdb52d04dc20036dbd8313ed055"
   * ,"name":"shen","gender":"\u5973","phoneNumber"
   * :"","email":"","description":"","beginTime":{},"endTime":{}}]
   */
  String json = null;
  try {
   json = gson.toJson(queryList);
   System.err.println(json);

  } catch (Exception e) {
   e.printStackTrace();
  }

  PrintWriter out = response().getWriter();

  out.print(json);
  out.flush();
  out.close();
  return null;
}
}

页面显示情况如下

 

 

 

你可能感兴趣的:(java笔记大全)