基于Spring3 MVC实现基于form表单上传Excel文件,批量导入数据!
来源:互联网 发布:mac怎么分区移动硬盘pc 编辑:程序博客网 时间:2024/05/16 08:14
在处理Excel文件,批量导入数据时,首先要配置所需要的jar包, 基于Spring MVC和Maven,在pom.xml中添加:
<span style="white-space:pre"></span><dependency> <groupId>net.sourceforge.jexcelapi</groupId> <artifactId>jxl</artifactId> <version>2.6.10</version></dependency>
在jsp页面中:
<div class="form-group"><form class="form-horizontal" method="post" action="${path}/master/child/importChild" id="fileUpload" name="fileUpload" enctype="multipart/form-data"><input class="form-control" type="file" id="excelFile" name="file"/><button class="btn btn-success" type="submit">批量上传 <i class="fa fa-upload"></i></button><span style="white-space:pre"></span></form></div>在MasterChildController.java中:
@RequestMapping(value = "importChild", method = RequestMethod.POST) public String importChild(HttpServletResponse response,MultipartHttpServletRequest request) throws Exception {//得到上传的文件 MultipartFile fileFile = request.getFile("file"); //转换成输入流 InputStream in = fileFile.getInputStream(); //得到Excel Workbook readWb = Workbook.getWorkbook(in); //得到sheet Sheet readSheet = readWb.getSheet(0); //得到多少列 int rsColumns = readSheet.getColumns(); //得到多少行 int rsRows = readSheet.getRows(); //单元格 Cell cell ; //实例化Child对象 Child child = new Child(); Map<Integer,String> map = new HashMap<Integer, String>(); for(int i=1;i<rsRows;i++) { for (int j = 0; j < rsColumns; j++) {cell = readSheet.getCell(j,i);map.put(j, cell.getContents());} child.setId(Atools.getOneKeyS()); String gradesName = map.get(0); //查询Grades对象Map<String, Object> params = new HashMap<String, Object>();params.put("gradesName", gradesName);List<Grades> grades = gradesService.queryAll(params);if(grades.size()>0 && grades.size()==1) {child.setGradesId(grades.get(0).getId());}child.setChildNo(map.get(1));child.setChildName(map.get(2));child.setSex(map.get(3));if(("男").equals((map.get(3)))) {child.setSex("1");}else if(("女").equals((map.get(3)))) {child.setSex("0");}else {child.setSex("0");}child.setAge(Integer.parseInt(map.get(4)));child.setBrithDay(map.get(5));Date date = new Date();child.setAddDate(date);child.setDr(map.get(6));child.setFatherName(map.get(7));child.setFatherPhone(map.get(8));child.setFatherWork(map.get(9));child.setMotherName(map.get(10));child.setMotherPhone(map.get(11));child.setMotherWork(map.get(12));child.setAddress(map.get(13));child.setComments(map.get(14));childService.addBean(child); }return reList; }综上所述:即可完成Java web中form表单提交Excel文件,批量上传数据!
1 0
- 基于Spring3 MVC实现基于form表单上传Excel文件,批量导入数据!
- 基于Spring3 MVC实现基于form表单上传Excel文件,批量导入数据时,报错:Unable to recognize OLE stream !
- 基于Spring3 MVC实现基于HTML form表单文件上传
- 基于Spring3 MVC实现批量导出数据成Excel文件!
- springMVC基于form表单上传Excel文件,导入数据
- 上传excel文件实现批量导入数据及导出数据为excel文件
- 基于annotation注解的Spring3 MVC Form Handling Example之二表单提交学习笔记
- EXCEL批量导入数据MVC
- Jquery+SpringMVC实现上传Excel文件,并批量导入
- Spring Mvc提交form表单上传文件
- Spring Mvc提交form表单上传文件
- mvc 利用form表单文件上传
- 基于表单的文件上传
- 基于表单的文件上传
- Apachepoi实现form表单上传Excel
- 基于spring3.0 MVC框架的文件上传(源码+解析)
- 上传文件实现数据采集以及批量导入数据库实例
- Spring3 MVC 文件上传
- [C#]解决第三方控件引起的"类型Universe无法解析程序集"问题
- 求一元二次方程的实根或虚根
- freemarker生成java代码
- gcc编译选项学习
- 为何moov头在尾部的mp4可以快速播放、拖动
- 基于Spring3 MVC实现基于form表单上传Excel文件,批量导入数据!
- Linux内核分析 实验七:Linux内核如何装载和启动一个可执行程序
- 深入理解SQL的四种连接-左外连接、右外连接、内连接、全连接
- 扣丁学堂笔记第27天NDK、屏幕适配与APP上线
- 剑指Offer——n个0到n-1的数里重复的数字
- 小米笔试题 风口的猪-中国牛市
- LeetCode 121 -Best Time to Buy and Sell Stock ( JAVA )
- F# 树
- 密码验证合格程序(华为oj)