Business operating System (v)

Source: Internet
Author: User

One, file asynchronous upload

The traditional form submission file upload refreshes the page and uses the Ocupload plugin to implement asynchronous uploads.

(1) Page section

(2) Action

 @Controller @scope ("prototype") public class Regionaction extends baseaction<region>{@Autowiredprivate Regionservice regionservice;private File myfile;private string Myfilefilename;public string Importexcel () throws Ioexception{if (MyFile! = null) {//Is Excelif (Myfilefilename.matches ("^.+\\. i) ((xls) | ( xlsx)) {String flag = "1"; Try{regionservice.importexcel (Myfile,myfilefilename);} catch (Exception e) {e.printstacktrace (); flag = "0";} Servletactioncontext.getresponse (). setContentType ("Text/html;charset=utf-8"); Servletactioncontext.getresponse (). Getwriter (). print (flag);}} return NONE;} public void Setmyfile (File myFile) {this.myfile = MyFile;} Public String Getmyfilefilename () {return myfilefilename;} public void Setmyfilefilename (String myfilefilename) {this.myfilefilename = Myfilefilename;}} 

(3) POI Read Excel

@Service @transactionalpublic class Regionserviceimpl implements regionservice{@Autowiredprivate Regiondao Regiondao; @Overridepublic void Importexcel (File myfile,string fileName) throws exception{list<region> List = new arraylist& Lt Region> (); Boolean is03excel = Filename.matches ("^.+\\. i) (XLS) $ "); FileInputStream InputStream = new FileInputStream (myFile);//1, read workbook workbook workbook = Is03excel? New Hssfworkbook (InputStream): New Xssfworkbook (InputStream);//2, read the first sheet sheet sheet = workbook.getsheetat (0);// Traversal gets each line for (row row:sheet) {//Gets the line number int num = Row.getrownum ();//The first row is not saved to the database if (num! = 0) {Row.getcell (0). Setcelltype ( cell.cell_type_string); Row.getcell (1). Setcelltype (cell.cell_type_string); Row.getcell (2). SetCellType (Cell.CELL_ type_string); Row.getcell (3). Setcelltype (cell.cell_type_string); Row.getcell (4). Setcelltype (Cell.CELL_TYPE_ string);//Gets the province and county string id = Row.getcell (0). Getstringcellvalue (); String province = Row.getcell (1). Getstringcellvalue (); String City = Row.getcell (2). GETstringcellvalue (); String district = Row.getcell (3). Getstringcellvalue (); String postcode = Row.getcell (4). Getstringcellvalue (); Region region = new Region (id,province,city,district,postcode,null,null,null); list.add;}} Regiondao.savebatch (list);}}
@Repositorypublic class Regiondaoimpl extends basedaoimpl<region> implements regiondao{@Overridepublic void Savebatch (list<region> List) {for [region Region:list] {saveorupdate (region);}}}

Business operating System (v)

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.