1
Study Plan
1. partition combination conditions paging query
N-page-separated query (no filter)
N-page-separated query (with filter conditions)
2. Partition Export
N Page Adjustment
n use POI to write data to an Excel file
n file download via output stream
3. Add the fixed area
N Fixed Area concept
n Fixed area Add page adjustment
N Server-side implementation
4, fixed page query
N Page Adjustment
N Server-side implementation
n Pagination Problem Summary
2
partition combination Condition paging query2.1
Separate page queries (no filter)
page: web-inf/pages/base/subarea.jsp
First step: Modify the URL address of the DataGrid in the JSP page
Step two: in Paging Query method is provided in suareaaction pagequery
Step Three: Modify subarea.hbm.xml
2.2
Separate page query (with filter)2.2.1
Page Adjustments
the DataGrid provides methods for resending Ajax requests, and can submit parameters
First step: Provide a tool method to convert all the entries in the specified form form to JSON data for parameter submissions
//defines a tool method for converting all entries in the specified form form to JSON data {Key:value,key:value}$.fn.serializejson=function(){ varserializeobj={}; vararray= This. Serializearray (); $ (array). each (function(){ if(serializeobj[ This. Name]) { if($.isarray (serializeobj[ This. Name])) {serializeobj[ This. Name].push ( This. Value); }Else{serializeobj[ This. name]=[serializeobj[ This. Name], This. value]; } }Else{serializeobj[ This. name]= This. Value; } }); returnSerializeobj; };
Step two: Bind the event to the query button in the Query window
$ ("#btn"). Click (function() { /// to convert all entries in the specified form form to JSON data {Key:value,key:value } var p = $ ("#searchForm"). Serializejson (); Console.info (p); // call the Load method of the data table, resend the AJAX request, and submit the parameters $ ("#grid"). DataGrid ("Load", p); // Close the query window $ ("#searchWindow"). Window ("close"); });
2.2.2
To Modify The paging query method in Action
/*** Paging Query*/ PublicString pagequery () {Detachedcriteria DC=Pagebean.getdetachedcriteria (); //dynamically add filter conditionsString Addresskey =Model.getaddresskey (); if(Stringutils.isnotblank (Addresskey)) {//add filter criteria, fuzzy query based on address keywordDc.add (Restrictions.like ("Addresskey", "%" +addresskey+ "%")); } Region=model.getregion (); if(Region! =NULL) {String province=region.getprovince (); String City=region.getcity (); String District=region.getdistrict (); Dc.createalias ("Region", "R"); if(Stringutils.isnotblank (province)) {//add filter conditions, according to the province fuzzy query-----Multi-Table association query, using the alias method to implement//parameter one: The associated Zone object property name in the partition object//parameter two: aliases, can be arbitraryDc.add (Restrictions.like ("r.province", "%" +province+ "%")); } if(Stringutils.isnotblank (city)) {//add filter conditions, according to the City Fuzzy query-----Multi-Table association query, using the alias method to implement//parameter one: The associated Zone object property name in the partition object//parameter two: aliases, can be arbitraryDc.add (Restrictions.like ("r.city", "%" +city+ "%")); } if(Stringutils.isnotblank (district)) {//add filter conditions, according to the area fuzzy query-----Multi-Table association query, using the alias method to implement//parameter one: The associated Zone object property name in the partition object//parameter two: aliases, can be arbitraryDc.add (Restrictions.like ("r.district", "%" +district+ "%")); }} subareaservice.pagequery (Pagebean); This. Java2json (Pagebean,Newstring[]{"CurrentPage", "Detachedcriteria", "PageSize", "Decidedzone", "subareas"}); returnNONE; }
Modify the method of paging query in Basedao
3
partition data export function3.1
Page Adjustments
To export a button binding event for a page
3.2
Service-Side implementation
The first step: querying all partition data
Step Two: Use POI writes data to an Excel file
Step three: Use the output stream for file download
/*** Partition Data export function *@throwsIOException*/ PublicString Exportxls ()throwsioexception{//The first step: querying all partition Datalist<subarea> list =Subareaservice.findall (); //Step Two: Use POI to write data to an Excel file//Create an Excel file in memoryHssfworkbook Workbook =NewHssfworkbook (); //Create a tab pageHssfsheet sheet = workbook.createsheet ("Partition Data"); //Create a header rowHssfrow Headrow = Sheet.createrow (0); Headrow.createcell (0). Setcellvalue ("Partition number")); Headrow.createcell (1). Setcellvalue ("Start numbering")); Headrow.createcell (2). Setcellvalue ("End number")); Headrow.createcell (3). Setcellvalue ("Location Information"); Headrow.createcell (4). Setcellvalue ("Provinces and cities"); for(Subarea subarea:list) {hssfrow DataRow= Sheet.createrow (Sheet.getlastrownum () + 1); Datarow.createcell (0). Setcellvalue (Subarea.getid ()); Datarow.createcell (1). Setcellvalue (Subarea.getstartnum ()); Datarow.createcell (2). Setcellvalue (Subarea.getendnum ()); Datarow.createcell (3). Setcellvalue (Subarea.getposition ()); Datarow.createcell (4). Setcellvalue (Subarea.getregion (). GetName ()); } //Step Three: Download the file using the output stream (one stream, two headers)String filename= "Partition data. xls"; String ContentType=Servletactioncontext.getservletcontext (). GetMimeType (filename); Servletoutputstream out=servletactioncontext.getresponse (). Getoutputstream (); Servletactioncontext.getresponse (). setContentType (ContentType); //Get the client browser typeString Agent = Servletactioncontext.getrequest (). GetHeader ("User-agent"); FileName=fileutils.encodedownloadfilename (filename, agent); Servletactioncontext.getresponse (). SetHeader ("Content-disposition", "attachment;filename=" +filename); Workbook.write (out); returnNONE; }
4
Fixed Zone Additions
The fixed area is the basic unit that carries on the distribution of the logistics, can relate the dispatch staff, the partition, the customer information, provides the data for the automatic splitting.
page: web-inf/pages/base/decidedzone.jsp
4.1
Page Adjustments4.1.1
Use the ComboBox to display the data of the dispatch staff
First step: Modify the ComboBox drop-down box URL address in the fixed area page
Step two: in The Listajax method is provided in the Staffaction , which queries all the non-deleted pick-up agents and returns the JSON
/** * Query all non-deleted Listajax, return JSON* /Public String () { List <Staff> list = staffservice.findlistnotdelete (); This New string[]{"Decidedzones"}); return NONE; }
step three: in extending a common query method in Basedao
Fourth step: in Staffservice in the extension method, query the non-deleted accessor
4.1.2
displaying partitioned data using the DataGrid
First step: Modify the URL address of the DataGrid in the page
Step two: in The Listajax method is provided in subareaaction , which queries all partitions that are not associated to the partition, and returns the JSON
step three: in Subareaservice extension methods, querying for partitions that are not associated to a region
4.1.3
submit a form for the Save button binding event
Issue One: Multiple ID parameters are present in the submitted form
Solution: Change the DataGrid 's filed from ID to subareaid
Question two: The value of the Subareaid parameter in the submitted form is null
Solution: Provide the Getsubareaid method in the partition class
4.2
Service-Side implementation
Create a fixed zone Action,Service,Dao
Service Code:
Configure Struts.xml
5
Fixed page Query
First step: Modify the URL address of the DataGrid in the fixed-area JSP page
Step Two: In the fixed area The pagequery method is provided in the Action
step three: in Decidedzone.hbm.xml , the associated accessor object needs to be loaded immediately when querying the bounding object
6
paged Query dead loop problem
1, the page does not need to show the associated data
FIX: Exclude associated object properties
2. When the page needs to show the associated data
WORKAROUND: Change the associated object to load immediately and exclude properties from the associated object
Javaee--bos Logistics Project 06: Paging query, partition export Excel file, add to the zone, pagination problem summary