1
Study Plan
1. Implement area Import function
N ocupload One-click Upload plugin to use
n upload the file to the Action
N POI Introduction
n using POI to parse an Excel file
N Complete Database operation
n generate simple code and City code using pinyin4j
2, regional paging query
N Page Adjustment
N Server-side implementation
3. Refactoring the paging code
N baseaction
N sub-class Action
4, partition add function
n What is a partition
N Page Adjustment (combobox use)
N Server-side implementation
2
Implementing the Zone Import feature2.1
jquery ocupload One-click Upload plugin to use
Ocupload(oneClick Upload)
First step: Introduce the JS file 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 two: Provide any element in the page
Step three: Invoke the Upload method provided by the plugin to dynamically modify HTML page elements
<script type= "Text/javascript" > $ (function() { // page load is complete, Call the plugin's upload method, dynamically modifying the HTML page element $ ("#myButton"). Upload ({ action:' xxx.action ', name: ' MyFile ' }) ; </script>
2.2
receiving uploaded files on the server
in the The Action provides a property of type file, the name is the same as the name of the uploaded document input box regionfile
@Controller @scope ("Prototype") Public classRegionactionextendsBaseaction<region>{ //Property-driven, receiving uploaded files PrivateFile Regionfile; Public voidsetregionfile (File regionfile) { This. Regionfile =Regionfile; } /*** Zone Import*/ PublicString Importxls () {System.out.println (regionfile); returnNONE; }}
2.3
Apache POI Technology
Apache POI is an open Source Library of the Apache Software Foundation , where POI provides APIs to Java program Read and write functionality for Microsoft Office format archives.
Download the development package:
Unzip the zip file above:
introducing in the project POI dependencies:
<Dependency> <groupId>Org.apache.poi</groupId> <Artifactid>Poi</Artifactid> <version>3.11</version> </Dependency>
POI use:
@Test Public voidTest1 ()throwsFileNotFoundException, ioexception{String filePath= "C:\\users\\zhaoqx\\desktop\\bos project (Dark Horse phase 32) \\BOS-day05\\ data \ Zone Import test data. xls"; //wrapping an Excel file ObjectHssfworkbook Workbook =NewHssfworkbook (NewFileInputStream (NewFile (FilePath)); //read the first sheet tab in a fileHssfsheet hssfsheet = workbook.getsheetat (0); //traverse all rows in a tab page for(Row row:hssfsheet) {System.out.println (); for(Cell cell:row) {String value=Cell.getstringcellvalue (); System.out.print (Value+ " "); } } }
2.4
pinyin4j
<!--introduction of pinyin4j dependency - <Dependency> <groupId>Com.belerweb</groupId> <Artifactid>Pinyin4j</Artifactid> <version>2.5.0</version> </Dependency>
@Test Public voidtest1 () {//Qiaoxi District, Shijiazhuang City, Hebei provinceString province = "Hebei province"; String City= "Shijiazhuang City"; String District= "Qiaoxi District"; //Jane code---->>HBSJZQXProvince= 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 Shortcode=Stringutils.join (headbystring); System.out.println (Shortcode); //City Code---->>shijiazhuangString Citycode = Pinyin4jutils.hanzitopinyin (city, ""); System.out.println (Citycode); }
3
area Data Paging query
Use the pagequery you've written before.
4
Refactoring the paging code
uniformly extracting duplicate code into in baseaction
5
partition Data add feature
Area is large, subdivision of region produces partition
5.1
Easyui ComboBox drop-down box using
make a json file:
<data-options= "url: ' ${pagecontext.request.contextpath}/json/combobox_data.json ', Valuefield: ' id ', textField: ' Name ' " class=" Easyui-combobox ">
5.2
use combobox to Show area data
page: web-inf/pages/base/subarea.jsp
First Step: Modify the ComboBox in the page :
Add method to get name
Step two: in Listajax methods available in regionaction
step three: in extension methods in Regiondao
Fourth step: Save the button binding event for the Add window
5.3
Service-Side implementation
create a partition corresponding to the Action,Service,Dao
6
Paging Query Problems
will be Java objects are converted to JSON because there is a cross-referencing relationship between objects, a dead loop problem occurs, a workaround is taken, and the attributes are excluded .
Javaee--bos Logistics Project 05:ocupload, POI, pinyin4j, refactoring pagination Code, partition additions, combobox