Chapter 14. javaWeb core technology of easyui

The site is back into the foreground of the site and the site. 
        Front - to see the user's example: mall 
        background - to the administrator to see for example: Mall backstage Objective: To maintain the data used to add 
    
    BootStrap: jsp page display, good effect, beautiful, suitable as a user interface. 
    EasyUI: JSP page, rapid development, unified format, the general aesthetic effect. 
    
    EasyUI there are many components (functional blocks): has its own special envoy, but they are written as simple as fixing html code structure. 
    
    EasyUI environment structures:
         1 . import css, requires two CSS
         2 introduced jquery, requires two JS.
             <Link the rel = "this stylesheet" type = "text / CSS" the href = "$ {} pageContext.request.contextPath / CSS / easyui. CSS "> 
            <Link the rel =" this stylesheet "type =" text / CSS "the href =" $ {} /css/icon.css pageContext.request.contextPath "> 
            <Link the rel =" this stylesheet "type =" text / CSS " href = "${pageContext.request.contextPath}/css/demo.css">
            <Script type = "text / JavaScript" the src = "$ {} /js/jquery.min.js pageContext.request.contextPath"> </ Script>
            <Script type = "text / JavaScript" the src = "$ {} /js/jquery.easyui.min.js pageContext.request.contextPath"> </ Script> 
                
    EasyUI defined manner: 
        easyui predetermined: we only need to provide a simple html code structure, special effects can be generated. 
            easyui defined manner:
                 . 1 .html code structure.
                     1.1: need class = "easyui- *" * represents the name of the component.
                     1.2: easyui provide additional properties: DATA- Options: which can be written property easyui provided. 
                        the Data - Options format: json format: Key: value, Key: value ......
                
                 2 .js rendering.
                     2.1 : syntax: Object component name ();.
                     2.2: Syntax: Component Object Name ({key: value, key: value .....}); 
                
                for example: 
                    HTML example:
                     <div class = "easyui-window" Data-Options = "title: 'the this title IS' , width: 200 is, height: 400 "> </ div> 
                    
                    js examples:
                     <div ID =" myDiv "> </ div> 
                    <Script> // If js rendering syntax: component Object name ({key: value , Key: value .....}); 
                        $ ( "# myDiv" ) .window ({ 
                            title: 'this is a new title' , 
                            width: 400 , 
                            height: 400 
                        }); </ Script>     
    the Easy - Properties - Events -
                        
                     method: 
        easyui attributes: event, method
            Properties: Component own characteristics, events and properties can be written with the format: key: value, key: value .... 
            Event: (passive) to complete the action after something triggered. 
                $ (Objects) component name ({. 
                    properties:, 
                    properties:, 
                    event: function 
                }) 
            
            method :( active) active member something done. 
            syntax: 
                . $ (target) parameters component name (method name, method)
                
             <div class = "easyui- Dialog "Data-Options =" width: 200 is, height: 200 is " , onBeforeClose: function () { 
                    Alert ( 'window will close' ); 
            } "> </ div>
             
            example:
                 <div ID = "myDiv2"> </ div>
                <input type = "button" value = " Close" onclick = "CloseDialog ()"> standard syntax setting method: $ (Object) component name (method name [value method]).
                <input type = "button" value = " open window" onclick = "OpenDialog ()"> // event 
                <Script of the type = "text / JavaScript"> 
                    $ ( "# myDiv2" ) .dialog ({ 
                        width: 200 , 
                        height : 200 is , 
                        onBeforeClose: function () { 
                            Alert ( 'window will close' ) 
                        } 
                    }); 
                function CloseDialog () { // 
                    . $ ( "# myDiv2") Dialog ( "Close" );
                }
                function openDiaLog() {
                
                
                    
                 
                    $ ( "# myDiv2") Dialog ( "Open." ); 
                }
         </ Script> 
    
    Form: 
        By default, the form is a traditional form, the traditional form synchronization, easyui form is asynchronous.
         <Script> 
            $ ( "#FF" ) .from ({ 
                URL: "$ {} pageContext.request.contextPath / DemoServlet", // equivalent action attribute, the path form submission. 
                the onSubmit: function () {
                     // here do efficacy, efficacy before the form is submitted.
                     // Alert (. 1);
                     // return to false; 
                },
                success:function(data) {
                     // callback function, the state where there is no code 200 is determined, the subsequent data is necessary to determine value.
                    Alert (Data) 
                } 
            });
         </ Script> 
    Tabs: Tab
         <Script> 
            function addTabs () { 
                var In Flag . = $ ( "# TT") tabs ( "EXISTS", "pay slips" ); 
                
                IF (In Flag ) {
                     // If the panel already exists, select the panel 
                    $ ( "# tt") tabs ( "select", " pay slips." ); 
                } the else {
                     // If the panel does not exist, add a panel 
                    $ ( "# tt" ) .tabs ( "the Add" , { 
                        title: "wage"  // title 
                        Content: "the Tab Body",   //Content 
                        the closable: to true   // Can off 
                        
                    }); 
                } 
                
            }
         </ Script> 
            
    drop-down box:
         <INPUT ID = "CC" name = "Dept" value = "select"> 
            <Script> 
                $ ( "#cc" ) .combobox ({
                     // load the remote event, support json easyui support json 
                    url: "combobox_data.json" , 
                    ValueField: "the above mentioned id", // the corresponding value value, json need to put the key here,   // < option value = ""> text </ Option> 
                    textFiedld: "  name " // Key text to be displayed on here
                    
                });
             </ Script> 
    
    the Datagrid: Data Form 
        url: load remote data support json 
            . Field Name field of the table, must json consistent, if they are consistent, the form is automatically filled json data
         <Table class = "easyui -datagrid "Data-Options =" URL: 'datagrid_data.json', Fit: to true "> 
            <thead> 
                <TR> 
                    <TH = Data-Options" Field: 'ID', width: 100 "> coding </ th> 
                    <th data-options = "field : 'name', width: 100"> name </ TH>
        </table> 
                    <TH Data-Options = "Field: ' age ', width: 100, align :' right ' ">Price </ th>
                    <th data-options = "field : 'pimage', width: 100, align: 'right', formatter: function (value, rows, index) {return '<img src =' + value + '>';}" > Photo </ TH> 
                </ TR> 
            </ thead> 
    
    <Table ID = "DG"> </ Table> 
        value: indicates the current json value 
        rows: row representing a current target 
        index: indicates the current row index
     <script> 
        $ ( '#dg' ) .datagrid ({     
            URL: 'datagrid_data.json', // URL: load remote data support JSON      
            Columns: [[     
                {Field: 'ID', title: 'ID', width: 100 } ,    
                {field:'name',title:'Name',width:100},    
                {Field: 'Age', title: 'Age', width: 100, align = left: 'right' }, 
                {Field: 'pImage', title: 'pImage', width: 100, align = left: 'right'right',
                    Formatter: function (value, rows, index) { 
                        return   "<IMG the src = '" + value + "' style = 'width: 40px'>" ; 
                       }     
                }     
            ]], 
            Fit: to true , // form automatically filled 
            fitColumns: to true , // columns are automatically filled 
            autoRowHeight: to true , // highly filled 
            Toolbar: [{ 
                iconCls: 'icon-edit' , 
                Handler: function () {Alert ( 'edit button' )} 
            }, '-' , { 
                iconCls: 'icon-Help' , 
                Handler: function () {Alert ( 'Help button' )} 
            }], 
            singleSelect: to true , // only select a 
            pagination: to true , // bottom of the page plus page article 
            pageNumber: 1, // default to open the first page 
            pageSize: 5 , 
            pageList: [ 5,10,15,20,25 , 30 ] 
        });  
     </ Script> 
    
    background Code: 
        received paging parameters: 
        the response data back: 
        
    protected  void doGet (HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
         the try {
             // Question 1: page requires incoming pageSize and pageNumber
             // Question 2: What is the response data page what data is needed to be paged? 
            
            // 0. coding 
            request.setCharacterEncoding ( "utf-8" ); 
            response.setHeader ( "Content-type", "text / HTML; charset = UTF-. 8" );
             // 1. obtaining data 
            String = pageNumberStr request.getParameter ( "Page" ); 
            String pageSizeStr = request.getParameter ( "rows" ); 
            
            int the pageNumber =int pageSize =Integer.valueOf (pageNumberStr);
             Integer.valueOf (pageSizeStr); // int = the pageNumber. 1;
             // int = the pageSize. 5; // 2. Data processing 
            the ProductService-Service = new new the ProductService ();
             // List <Product> = plist service.findAll ();
             // if the response does not go back to the list only paging
             // List <Product> = service.findByPage plist (the pageNumber, the pageSize); 
            easyUIPageBean <Product> easyUIPageBean = service.findByEasyUIPage (the pageNumber, the pageSize); // data requiring a response {total: 28, "rows" : [{}, {}, {}]} == >> map can be packaged objects
             @
            
            
            
            
            
             but is [{key: value, key: value}, {key: value , key: value} ..]
            
            
            // 3.响应 
            Gson gson = new Gson (); 
            String json = gson.toJson (easyUIPageBean); 
            System.out.println (json); 
            response.getWriter (). print (json); 
        } Catch (Exception e) { 
            e.printStackTrace (); 
        } 
    
    }

 

Guess you like

Origin www.cnblogs.com/haizai/p/11442990.html