JAVAEE--BOS logistics project 05: OCUpload, POI, pinyin4J, refactoring paging code, partition addition, combobox, javaeeocupload

Source: Internet
Author: User

JAVAEE--BOS logistics project 05: OCUpload, POI, pinyin4J, refactoring paging code, partition addition, combobox, javaeeocupload
1Learning plan

1. Implement the regional import function

N OCUpload one-Click Upload plug-in

N upload files to Action

Introduction to n POI

N use POI to parse Excel files

N complete database operations

N use pinyin4J to generate short codes and city codes

2. Area paging Query

N page Adjustment

N server implementation

3. Rebuild the paging code

N BaseAction

N subclass Action

4. Add partitions

N what is a partition?

N page adjustment (used by combobox)

N server implementation

 

 

2 Implement the regional import function2.1 Jquery OCUpload one-Click Upload plug-in

OCUpload (One Click Upload)

Step 1: Introduce js files to the page

<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script><script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery.ocupload-1.1.2.js"></script>

Step 2: Provide any element on the page

 

Step 3: Call the upload method provided by the plug-in to dynamically modify HTML page elements

<Script type = "text/javascript"> $ (function () {// After the page is loaded, call the upload method of the plug-in, the HTML page element $ ("# myButton") is dynamically modified "). upload ({action: 'xxx. action ', name: 'myfile'}) ;}</script>

 

 

2.2 Receive uploaded files on the server

Provide a File type attribute in Action. The name is the same as the name of the uploaded File input box regionFile.

@ Controller @ Scope ("prototype") public class RegionAction extends BaseAction <Region> {// property driver, receives the uploaded File private File regionFile; public void setRegionFile (File regionFile) {this. regionFile = regionFile;}/*** import region */public String importXls () {System. out. println (regionFile); return NONE ;}}

 

2.3 Apache POI Technology

Apache POI is an open-source library of the Apache Software Foundation. POI provides APIs for Java programs to read and write Microsoft Office files.

 

Download the SDK:

 

 

Decompress the zip file above:

 

 

 

Introduce the dependency of POI in the project:

        <dependency>            <groupId>org.apache.poi</groupId>            <artifactId>poi</artifactId>            <version>3.11</version>        </dependency>

 

POI usage:

@ Test public void test1 () throws FileNotFoundException, IOException {String filePath = "C: \ Users \ zhaoqx \ Desktop \ BOS Project (black horse phase 32) \ BOS-day05 \ Documents import test data .xls "; // wrap an Excel File object HSSFWorkbook workbook = new HSSFWorkbook (new FileInputStream (new File (filePath ))); // read the first Sheet tab in the file. HSSFSheet hssfSheet = workbook. getSheetAt (0); // traverses all rows in the tab for (Row row: hssfSheet) {System. out. println (); for (Cell cell: row) {String value = cell. getStringCellValue (); System. out. print (value + "");}}}

 

2.4 Pinyin4J

 

<! -- Introduce dependencies of pinyin4J --> <dependency> <groupId> com. belerweb </groupId> <artifactId> pinyin4j </artifactId> <version> 2.5.0 </version> </dependency>

 

@ Test public void test1 () {// String province = "Hebei province"; String city = "Shijiazhuang city"; String district = "qiaoxi district "; // simple code ----> HBSJZQX province = province. substring (0, province. length ()-1); city = city. substring (0, city. length ()-1); district = district. substring (0, district. length ()-1); String info = province + city + district; String [] headByString = PinYin4jUtils. getHeadByString (info); String response code = StringUtils. join (headByString); System. out. println (city code); // city code ----> shijiazhuang String citycode = PinYin4jUtils. hanziToPinyin (city, ""); System. out. println (citycode );}

 

 

3 Area Data paging Query

Use the previously written pageQuery

 

4 Rebuild paging code

Extract duplicate code into BaseAction

 

 

 

5 Partition data Addition

The region range is large, and partitions are generated by dividing the region.

 

5.1 EasyUI combobox drop-down box

Create a json file:

 

    <input data-options="url:'${pageContext.request.contextPath }/json/combobox_data.json',            valueField:'id',            textField:'name'"             class="easyui-combobox">

 

 

5.2 Use combobox to display regional data

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

 

 

 

Step 1: Modify the combobox on the page:

 

 

Add a method to obtain the name

 

 

 

Step 2: Provide the listajax method in RegionAction

 

 

Step 3: Expand the method in RegionDao

 

 

Step 4: bind an event to the Save button in the Add window

 

 

 

5.3 Server implementation

Create Action, Service, and Dao corresponding to the partition

 

6 Paging query Problems

In the process of converting a Java object to a json object, an endless loop occurs because the objects are referenced by each other. The solution is to exclude the attributes.

 

 

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.