Complete one page with the DataGrid

Source: Internet
Author: User

Playing strange upgrade is really difficult, record a little bit, a drop, first on.

1. To complete an interface, you have to have an interface first. The interface is established in the new zjqktj.jsp in the root directory file under Webroot, and then the database is retrieved by Java in the background to implement the graph display. Here the hint refers to the CSS framework in Easyui, and the zjqktj.jsp code shows:

<%@ page language= "Java"Import= "java.util.*" pageencoding= "Utf-8"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >class= "Easyui-datagrid" data-options= "url: ' zjqktj.do ', title: ' Installed condition statistics '" > <thead> <tr> <th data-options= "field: ' Dzmc ', width:100" > Plant name </th> <th data-options= "Fiel D: ' Sjzjrl ', width:100 "> Design Installed Capacity (MW) </th> <th data-options=" field: ' Ytcrl ', width:100 "> Production capacity (MW ) </th> <th data-options= "field: ' Azfszl ', width:100" > Installation type (type) </th> < Th data-options= "field: ' Nbqcjs ', width:100" > Inverter Manufacturers (Home) </th> <th data-options= "field: ' NBQSL ', width : "> Number of Inverters (set) </th> <th data-options=" field: ' Njhdxlyxss ', width:100 "> Annual plan Equivalent Utilization hours (h) </th&gt                 ; </tr> </thead> </table> </div> </body>

2. The front-end interface is ready, create a new Java class in the model package. The introduction of the package, the definition of variables, database connections, SQL statements are not less. The last part of the comment is the code to test whether the data can be taken after writing, right click on the blank interface, select "Debug as".

 PackageCom.pv.model;ImportJava.sql.*;Importjava.util.ArrayList; Public classGETZJQKTJ { PublicArrayList GETZJQKTJ (String username)throwssqlexception{//remove groups based on user nameStatement st=NULL; ResultSet RS=NULL; Connection CT=NULL; ArrayList Al=NewArrayList (); Try{             //Remove all plant information from the userCt= (NewConnectdb ()).            Conndb (); St=ct.createstatement (); RS=st.executequery ("Select a. ' Power plant name ', a. ' Installed Capacity ', a. ' already in production volume ', Count (DISTINCT B. ' manufacturer ') as the number of manufacturers, COUNT (DISTINCT A. ' Installation method ') as Installation type , COUNT (B. ' Device ID ') as the number of inverters, ROUND (d. ' Annual total capacity '/a. ' Installed Capacity ', 2) as Year Plan equivalent utilization hours from ' Plant Information list ' A, ' inverter information list ' B, ' User Information table ' C, ' Power station monthly statistics ' D wher E A. ' Power plant code ' =b. ' Group List _ Power station code ' + ' and a. ' Plant code ' =c. ' Power station information list ' and a. ' Plant code ' =d. ' Plant Information List _ Power station code ' and C. ' User name ' = ' "+username+" ' GROUP by a. ' Plant code ' ");  while(Rs.next ()) {String[]str=NewString[7]; str[0]=rs.getstring (1); str[1]=rs.getstring (2); str[2]=rs.getstring (3); str[3]=rs.getstring (4); str[4]=rs.getstring (5); str[5]=rs.getstring (6); str[6]=rs.getstring (7);              Al.add (str); }            }Catch(Exception e) {e.printstacktrace (); }          returnal; }}//Public static void Main (string[] args) throws sqlexception{//getzjqktj zz=new getzjqktj ();//ArrayList al=zz.getzjqktj ("Yangyang");//for (int i=0;i<al.size (); i++)//        { //string[] str= (string[]) al.get (i);//for (int j=0;j<str.length;j++) {//System.out.println (Str[j]); }//        }//        }//            //        //    }     

3. In order to achieve the elegance of JSP pages, do not add Java fragments. Therefore, the new Zjqktjcontroller.java class is created in the controller package, and the data extracted from the database is directly mapped to the front-end interface via JSON parameters, which needs to be digested.

 PackageCom.pv.control;Importjava.io.IOException;Importjava.sql.SQLException;Importjava.util.ArrayList;ImportJava.util.HashMap;ImportJava.util.Map;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportCom.alibaba.fastjson.JSONArray;ImportCom.alibaba.fastjson.JSONObject;ImportCom.pv.model.GetGroup;Importcom.pv.model.GetZjqktj; @Controller Public classZjqktjcontroller {@RequestMapping (value= "Zjqktj.do")     Public voidZJQKTJ (httpservletrequest req,httpservletresponse Res)throwsIOException, sqlexception{Map<string, object> result =NewHashmap<string, object> (2) ; String username= (String) req.getattribute ("username"); Res.setcharacterencoding ("Utf-8"); Jsonarray Jsonarray=NewJsonarray (); GETZJQKTJ ZZ=NewGETZJQKTJ (); ArrayList Al=ZZ.GETZJQKTJ ("Yangyang"); if(Al.size () ==0)        {                    }        Else {             for(intI=0;i<al.size (); i++) {Jsonobject jsonobject=NewJsonobject (); string[] Str=(string[]) al.get (i); Jsonobject.put ("DZMC", str[0]); Jsonobject.put ("Sjzjrl", str[1]); Jsonobject.put ("Ytcrl", str[2]); Jsonobject.put ("Nbqcjs", str[3]); Jsonobject.put ("Azfszl", str[4]); Jsonobject.put ("NBQSL", str[5]); Jsonobject.put ("Njhdxlyxss", str[6]);        Jsonarray.add (Jsonobject); } result.put ("Total", 1); Result.put ("Rows", Jsonarray); Object o=Jsonobject.tojson (Result);                Res.getwriter (). Write (o.tostring ());                Res.getwriter (). Flush ();                Res.getwriter (). Close (); }    }    }

4. You need to harden the basic syntax, or try to implement the interface in another way. Climb slowly, then learn to walk.

Complete one page with the DataGrid

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.