@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(@RequestParam
MultipartFile file,@RequestParam(required=false) Integer importFlag, HttpServletRequest request, HttpServletResponse response)
throws IOException {
// 如果只是上传一个文件,则只需要MultipartFile类型接收文件即可,而且无需显式指定@RequestParam注解
// 如果想上传多个文件,那么这里就要用MultipartFile[]类型来接收文件,并且还要指定@RequestParam注解
// 并且上传多个文件时,前台表单中的所有<input
// type="file"/>的name都应该是myfiles,否则参数里的myfiles无法获取到所有上传的文件
int flag = 0;
String json;
if (file.isEmpty()) {
System.out.println("文件未上传");
} else {
// 如果用的是Tomcat服务器,则文件会上传到\\%TOMCAT_HOME%\\webapps\\YourWebProject\\WEB-INF\\upload\\文件夹中
String realPath = request.getSession().getServletContext()
.getRealPath("/upload");
// 这里不必处理IO流关闭的问题,因为FileUtils.copyInputStreamToFile()方法内部会自动把用到的IO流关掉,我是看它的源码才知道的
File xlsFile = new File(realPath, file.getOriginalFilename());
FileUtils.copyInputStreamToFile(file.getInputStream(), xlsFile); HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
xlsFile)); HSSFSheet sheet = workbook.getSheetAt(0);
List<Salary> salaryList = new ArrayList<Salary>();
Salary salary = null;
HSSFRow row = null; for (int i = 2; i < sheet.getLastRowNum() + 1; i++) { row = sheet.getRow(i);
salary = new Salary();
//部门编号
salary.setDeptCode(getCellValue(row.getCell(0)));
//部门名
salary.setDeptName(getCellValue(row.getCell(1)));
//工号
salary.setStaffCode(getCellValue(row.getCell(2)));
//姓名
salary.setRealName(getCellValue(row.getCell(3)));
//岗资
salary.setPostWage(getCellValue(row.getCell(4)));
//薪资
salary.setPay(getCellValue(row.getCell(5)));
//绩效
salary.setMeritPay(getCellValue(row.getCell(6)));
// 岗位津贴
salary.setTask(getCellValue(row.getCell(7)));
// 保留贴
salary.setResponsibility(getCellValue(row.getCell(8)));
//课酬
salary.setKeep(getCellValue(row.getCell(9)));
//其他
salary.setNet(getCellValue(row.getCell(10)));
//补公积
salary.setProvident(getCellValue(row.getCell(11)));
// 岗补
salary.setBack(getCellValue(row.getCell(12)));
// 课补
salary.setBack2(getCellValue(row.getCell(13))); //临补
salary.setTemporyBack(getCellValue(row.getCell(14)));
//应发额
salary.setWages(getCellValue(row.getCell(15)));
// 工会
salary.setLabour(getCellValue(row.getCell(16)));
//失业保险
salary.setUnemployed(getCellValue(row.getCell(17)));
// 医疗保险
salary.setMedical(getCellValue(row.getCell(18)));
// 扣公积
salary.setDeductionProvident(getCellValue(row.getCell(19)));
// 扣一
salary.setDeductionOne(getCellValue(row.getCell(20)));
// 扣
salary.setReserved(getCellValue(row.getCell(21)));
// 养老保险
salary.setPension(getCellValue(row.getCell(22)));
//税所得
salary.setAfterTaxIncome(getCellValue(row.getCell(23)));
// 所得税
salary.setIncomeTax(getCellValue(row.getCell(24)));
//Totaldeductio
salary.setTotaldeduction(getCellValue(row.getCell(25)));
//实发额
salary.setHomepay(getCellValue(row.getCell(26)));
salary.setYear(getCellValue(row.getCell(27)));
salary.setMonth(getCellValue(row.getCell(28)));
salary.setNote(getCellValue(row.getCell(29)));
salaryList.add(salary); } if (salaryList.size() > 0) {
flag = salaryService.insert(salaryList,importFlag);
if (flag > 0) {
xlsFile.delete(); }
}
} if (flag > 0) {
json = "{\"success\":\"true\",\"msg\":\"导入成功!\"}";
} else {
json = "{\"success\":\"false\"}";
}
response.setContentType("text/html;charset=utf-8"); try {
response.getWriter().write(json);
response.getWriter().flush();
response.getWriter().close();
} catch (IOException e) {
e.printStackTrace();
} }

springmvc多文件上传的更多相关文章

  1. springmvc图片文件上传接口

    springmvc图片文件上传 用MultipartFile文件方式传输 Controller package com.controller; import java.awt.image.Buffer ...

  2. SpringMVC学习--文件上传

    简介 文件上传是web开发中常见的需求之一,springMVC将文件上传进行了集成,可以方便快捷的进行开发. springmvc中对多部件类型解析 在 页面form中提交enctype="m ...

  3. Spring +SpringMVC 实现文件上传功能。。。

    要实现Spring +SpringMVC  实现文件上传功能. 第一步:下载 第二步: 新建一个web项目导入Spring 和SpringMVC的jar包(在MyEclipse里有自动生成spring ...

  4. SpringMVC之文件上传异常处理

    一般情况下,对上传的文件会进行大小的限制.如果超过指定大小时会抛出异常,一般会对异常进行捕获并友好的显示出来.以下用SpringMVC之文件上传进行完善. 首先配置CommonsMultipartRe ...

  5. springmvc实现文件上传

    springmvc实现文件上传 多数文件上传都是通过表单形式提交给后台服务器的,因此,要实现文件上传功能,就需要提供一个文件上传的表单,而该表单就要满足以下3个条件 (1)form表彰的method属 ...

  6. 【SpringMVC】文件上传Expected MultipartHttpServletRequest: is a MultipartResolver错误解决

    本文转载自:https://blog.csdn.net/lzgs_4/article/details/50465617 使用SpringMVC实现文件上传时,后台使用了 MultipartFile类, ...

  7. 关于SpringMVC的文件上传

    关于文件的上传,之前写过2篇文章,基于Struts2框架,下面给出文章链接: <关于Struts2的文件上传>:http://www.cnblogs.com/lichenwei/p/392 ...

  8. 一起学SpringMVC之文件上传

    概述 在Web系统开发过程中,文件上传是普遍的功能,本文主要以一个简单的小例子,讲解SpringMVC中文件上传的使用方法,仅供学习分享使用,如有不足之处,还请指正. 文件上传依赖包 如下所示,文件上 ...

  9. SpringMVC+ajax文件上传实例教程

    原文地址:https://blog.csdn.net/weixin_41092717/article/details/81080152 文件上传文件上传是项目开发中最常见的功能.为了能上传文件,必须将 ...

  10. 6.学习springmvc的文件上传

    一.文件上传前提与原理分析 1.文件上传必要前提: 2.文件上传原理分析: 3.需要引入的jar包: 二.传统方式文件上传程序 1.pom.xml <dependency> <gro ...

随机推荐

  1. 微信或移动端网页的meta

    针对微信: <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> ...

  2. Java-Linux系统中搭建开发环境

    准备工作: 0.虚拟机中的系统→{RHEL-I386} 1.JDK→{首先要知道下载哪个版本" [zf@string ~]$ getconf LONG_BIT ":".t ...

  3. ZOJ 3201 Tree of Tree

    树形DP.... Tree of Tree Time Limit: 1 Second      Memory Limit: 32768 KB You're given a tree with weig ...

  4. 点击验证码刷新(tp3.1)--超简单

    省略js点击刷新验证码,虽然看不懂 <img src='http://localhost/app/index.php/Index/verify/'  onclick='this.src=this ...

  5. Hadoop之Storm安装

    nimbus:主节点,负责分发代码,分配任务(只能有一个)supervisor:从节点,负责执行任务(可以有多个) jdkzookeeper(192.168.1.170/171/172)建议在zook ...

  6. C++ 错误总结

    1.出现不完全的类型‘class CJdThread’的非法使用或前向声明 src/../include/ComCommon.h:37:27: 错误:对不完全的类型‘class CJdThread’的 ...

  7. excle心得及部分应用案例

    目前数据分析方面的知识还学的不多,以后会持续向一些大牛学习,不断的学会做笔记,这样既加深了理解,也能够和大家分享交流.今天就只是把一些excle中常用的知识点总结啦~作为我博客的第一篇吧,希望自己能够 ...

  8. android之inflater用法

    在实际开发中LayoutInflater这个类还是非常有用的,它的作用类似于findViewById().不同点是LayoutInflater是用来找res/layout/下的xml布局文件,并且实例 ...

  9. BZOJ 4423: [AMPPZ2013]Bytehattan

    Sol 对偶图+并查集. 思路非常好,将网格图转化成对偶图,在原图中删掉一条边,相当于在对偶图中连上一条边(其实就是网格的格点相互连边),每次加边用并查集维护就可以了. 哦对,还要注意边界就是网格外面 ...

  10. BZOJ 4547: Hdu5171 小奇的集合

    Sol 首先,考虑这个要怎么搞...让总和最大的方法就是选出当前集合中最大的两个数相加放入集合中就可以了,证明非常简单,当前集合的和为x,它的和只会一直往后增加,所以只需要找到最大的两个数的和加入便是 ...