JAVAEE--BOS logistics project 06: Paging query, partition export Excel file, add area, paging problem summary, javaee Logistics Project

Source: Internet
Author: User

JAVAEE--BOS logistics project 06: Paging query, partition export Excel file, add area, paging problem summary, javaee Logistics Project
1Learning plan

1. Partition combination condition paging Query

N partition paging query (no filtering conditions)

N partition paging query (with filtering conditions)

2. Partition Export

N page Adjustment

N use POI to write data to an Excel file

N downloads files through the output stream

3. Add a zone

N partition Concept

Adjust the n-zone addition page

N server implementation

4. Area-based paging Query

N page Adjustment

N server implementation

N paging problem summary

 

2 Partition combination condition paging Query2.1 Partition paging query (no filtering conditions)

Page: WEB-INF/pages/base/subarea. jsp

Step 1: Modify the URL of the datagrid on the jsp page

 

 

Step 2: Provide the pageQuery method in SuareaAction

 

 

Step 3: Modify subarea. hbm. xml

 

 

2.2 Partition paging query (with filtering conditions)2.2.1 Page Adjustment

 

 

Method provided by datagrid: Used to resend ajax requests and submit Parameters

 

 

 

Step 1: provide a tool method to convert all input items in the specified form into json data for parameter submission.

// Define a tool method to convert all input items in the specified form into json data {key: value, key: value} $. fn. serializeJson = function () {var serializeObj ={}; var array = 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 ;}}); return serializeObj ;};

 

Step 2: bind an event to the query button in the query window

 

$ ("# Btn "). click (function () {// convert all input items in the specified form into json data {key: value, key: value} var p = $ ("# searchForm "). serializeJson (); console.info (p); // call the load method of the data table, resend an ajax request, and submit the parameter $ ("# grid "). datagrid ("load", p); // close the query window $ ("# searchWindow "). window ("close ");});

 

2.2.2 Modify the paging query method in Action

 

/*** Paging query */public String pageQuery () {DetachedCriteria dc = pageBean. getDetachedCriteria (); // dynamically Add the filter condition String addresskey = model. getAddresskey (); if (StringUtils. isNotBlank (addresskey) {// Add a filter condition and fuzzy query dc based on the address keyword. add (Restrictions. like ("addresskey", "%" + addresskey + "%");} Region 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, fuzzy query by province ----- multi-table join query, using the alias method // parameter 1: attribute name of the region object associated with the partition object // parameter 2: alias, which can be any dc. add (Restrictions. like ("r. province "," % "+ province +" % ");} if (StringUtils. isNotBlank (city) {// Add a filter condition, according to the city fuzzy query ----- multi-Table association query, using the alias method // parameter 1: attribute name of the region object associated with the partition object // parameter 2: alias, which can be any dc. add (Restrictions. like ("r. city "," % "+ city +" % ");} if (StringUtils. isNotBlank (district) {// Add filter conditions, fuzzy query by region ----- multi-table join query, using the alias method // parameter 1: attribute name of the region object associated with the partition object // parameter 2: alias, which can be any dc. add (Restrictions. like ("r. district "," % "+ district +" % ") ;}} subareaService. pageQuery (pageBean); this. java2Json (pageBean, new String [] {"currentPage", "detachedCriteria", "pageSize", "decidedzone", "subareas"}); return NONE ;}

 

Modify the paging query method in BaseDao

 

 

 

3 Partition data export Function3.1 Page Adjustment

Bind events to the export button on the page

 

 

3.2 Server implementation

Step 1: Query all partition data

Step 2: Use POI to write data to an Excel file

Step 3: Use the output stream for File Download

/*** Partition data export function ** @ throws IOException */public String exportXls () throws IOException {// Step 1: query the List of all partition data <Subarea> list = subareaService. findAll (); // Step 2: Use POI to write data to an Excel file // create an Excel file HSSFWorkbook workbook = new HSSFWorkbook () in the memory (); // create a tab named HSSFSheet sheet = workbook. createSheet ("partition data"); // create the header row HSSFRow headRow = sheet. createRow (0); headRow. createCell (0 ). setCellValue ("Partition Number"); headRow. createCell (1 ). setCellValue ("START number"); headRow. createCell (2 ). setCellValue ("end number"); headRow. createCell (3 ). setCellValue ("location information"); headRow. createCell (4 ). setCellValue ("province city"); 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 3: Use the output stream for file download (one stream and two headers) String filename = "partition data .xls"; String contentType = ServletActionContext. getServletContext (). getMimeType (filename); ServletOutputStream out = ServletActionContext. getResponse (). getOutputStream (); ServletActionContext. getResponse (). setContentType (contentType); // obtain the client browser type String agent = ServletActionContext. getRequest (). getHeader ("User-Agent"); filename = FileUtils. encodeDownloadFilename (filename, agent); ServletActionContext. getResponse (). setHeader ("content-disposition", "attachment; filename =" + filename); workbook. write (out); return NONE ;}

 

 

4 Add a zone

A specific area is the basic unit for logistics distribution. It can associate dispatched personnel, partitions, and customer information to provide data for automatic order splitting.

WEB-INF/pages/base/decidedzone. jsp

 

 

 

4.1 Page Adjustment4.1.1 Use combobox to display Dispatch Data

Step 1: Modify the combobox drop-down box URL

 

 

 

Step 2: Provide the listajax method in StaffAction to query all undeleted dispatchers and return the json

/*** Query all undeleted dispatchers and return json */public String listajax () {List <Staff> list = staffService. findListNotDelete (); this. java2Json (list, new String [] {"decidedzones"}); return NONE ;}

 

Step 3: expand a common query method in BaseDao

 

 

Step 4: Expand the method in StaffService to query undeleted dispatchers.

 

 

 

4.1.2 Display partition data using datagrid

Step 1: Modify the URL of the datagrid on the page

 

Step 2: Provide the listajax method in SubareaAction to query all partitions that are not associated with a specific zone. Return json

 

 

Step 3: Expand the method in SubareaService to query partitions not associated with a specific partition.

 

 

 

 

4.1.3 Bind an event submission form to the Save button

 

 

Problem 1: The submitted form contains multiple id parameters.

 

 

Solution: Change the filed of the datagrid from id to subareaid.

 

 

Question 2: The subareaid parameter value in the submitted form is null.

 

 

Solution: Provide the getSubareaid method in the partition class.

 

 

4.2 Server implementation

Create zone-specific actions, services, and Dao

 

 

Service Code:

 

 

 

Configure struts. xml

 

 

 

5 Area-based paging Query

Step 1: Modify the datagrid URL on the custom jsp page

 

 

Step 2: Provide the pageQuery method in the specific Action.

 

 

Step 3: Modify in Decidedzone. hbm. xml. When querying a specific area object, you need to load the associated dispatch object immediately.

 

 

6 Endless loop in paging Query

1. When the page does not need to display associated data

Solution: exclude associated Object Attributes

 

2. When the page needs to display associated data

Solution: Change the associated object to load immediately and exclude the attributes of the associated object.

 

Related Article

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.