1. @RequestMapping(value = "/upload", method = RequestMethod.POST)
  2. public void upload(@RequestParam
  3. MultipartFile file,@RequestParam(required=false) Integer importFlag, HttpServletRequest request, HttpServletResponse response)
  4. throws IOException {
  5. // 如果只是上传一个文件,则只需要MultipartFile类型接收文件即可,而且无需显式指定@RequestParam注解
  6. // 如果想上传多个文件,那么这里就要用MultipartFile[]类型来接收文件,并且还要指定@RequestParam注解
  7. // 并且上传多个文件时,前台表单中的所有<input
  8. // type="file"/>的name都应该是myfiles,否则参数里的myfiles无法获取到所有上传的文件
  9. int flag = 0;
  10. String json;
  11. if (file.isEmpty()) {
  12. System.out.println("文件未上传");
  13. } else {
  14. // 如果用的是Tomcat服务器,则文件会上传到\\%TOMCAT_HOME%\\webapps\\YourWebProject\\WEB-INF\\upload\\文件夹中
  15. String realPath = request.getSession().getServletContext()
  16. .getRealPath("/upload");
  17. // 这里不必处理IO流关闭的问题,因为FileUtils.copyInputStreamToFile()方法内部会自动把用到的IO流关掉,我是看它的源码才知道的
  18. File xlsFile = new File(realPath, file.getOriginalFilename());
  19. FileUtils.copyInputStreamToFile(file.getInputStream(), xlsFile);
  20.  
  21. HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(
  22. xlsFile));
  23.  
  24. HSSFSheet sheet = workbook.getSheetAt(0);
  25. List<Salary> salaryList = new ArrayList<Salary>();
  26. Salary salary = null;
  27. HSSFRow row = null;
  28.  
  29. for (int i = 2; i < sheet.getLastRowNum() + 1; i++) {
  30.  
  31. row = sheet.getRow(i);
  32. salary = new Salary();
  33. //部门编号
  34. salary.setDeptCode(getCellValue(row.getCell(0)));
  35. //部门名
  36. salary.setDeptName(getCellValue(row.getCell(1)));
  37. //工号
  38. salary.setStaffCode(getCellValue(row.getCell(2)));
  39. //姓名
  40. salary.setRealName(getCellValue(row.getCell(3)));
  41. //岗资
  42. salary.setPostWage(getCellValue(row.getCell(4)));
  43. //薪资
  44. salary.setPay(getCellValue(row.getCell(5)));
  45. //绩效
  46. salary.setMeritPay(getCellValue(row.getCell(6)));
  47. // 岗位津贴
  48. salary.setTask(getCellValue(row.getCell(7)));
  49. // 保留贴
  50. salary.setResponsibility(getCellValue(row.getCell(8)));
  51. //课酬
  52. salary.setKeep(getCellValue(row.getCell(9)));
  53. //其他
  54. salary.setNet(getCellValue(row.getCell(10)));
  55. //补公积
  56. salary.setProvident(getCellValue(row.getCell(11)));
  57. // 岗补
  58. salary.setBack(getCellValue(row.getCell(12)));
  59. // 课补
  60. salary.setBack2(getCellValue(row.getCell(13)));
  61.  
  62. //临补
  63. salary.setTemporyBack(getCellValue(row.getCell(14)));
  64. //应发额
  65. salary.setWages(getCellValue(row.getCell(15)));
  66. // 工会
  67. salary.setLabour(getCellValue(row.getCell(16)));
  68. //失业保险
  69. salary.setUnemployed(getCellValue(row.getCell(17)));
  70. // 医疗保险
  71. salary.setMedical(getCellValue(row.getCell(18)));
  72. // 扣公积
  73. salary.setDeductionProvident(getCellValue(row.getCell(19)));
  74. // 扣一
  75. salary.setDeductionOne(getCellValue(row.getCell(20)));
  76. // 扣
  77. salary.setReserved(getCellValue(row.getCell(21)));
  78. // 养老保险
  79. salary.setPension(getCellValue(row.getCell(22)));
  80. //税所得
  81. salary.setAfterTaxIncome(getCellValue(row.getCell(23)));
  82. // 所得税
  83. salary.setIncomeTax(getCellValue(row.getCell(24)));
  84. //Totaldeductio
  85. salary.setTotaldeduction(getCellValue(row.getCell(25)));
  86. //实发额
  87. salary.setHomepay(getCellValue(row.getCell(26)));
  88. salary.setYear(getCellValue(row.getCell(27)));
  89. salary.setMonth(getCellValue(row.getCell(28)));
  90. salary.setNote(getCellValue(row.getCell(29)));
  91. salaryList.add(salary);
  92.  
  93. }
  94.  
  95. if (salaryList.size() > 0) {
  96. flag = salaryService.insert(salaryList,importFlag);
  97. if (flag > 0) {
  98. xlsFile.delete();
  99.  
  100. }
  101. }
  102. }
  103.  
  104. if (flag > 0) {
  105. json = "{\"success\":\"true\",\"msg\":\"导入成功!\"}";
  106. } else {
  107. json = "{\"success\":\"false\"}";
  108. }
  109. response.setContentType("text/html;charset=utf-8");
  110.  
  111. try {
  112. response.getWriter().write(json);
  113. response.getWriter().flush();
  114. response.getWriter().close();
  115. } catch (IOException e) {
  116. e.printStackTrace();
  117. }
  118.  
  119. }

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. LINUX系统知识(转)

    原文链接:http://blog.chinaunix.net/uid-725717-id-2060377.html 在Linux上配置好svnserve,通过eclipse访问,实现版本控制.但是开启 ...

  2. HTTP状态301、404、200、304分别表示什么意思

    301 (永久移动)请求的网页已永久移动到新位置.服务器返回此响应(对 GET 或 HEAD 请求的响应)时,会自动将请求者转到新位置.您应使用此代码告诉 Googlebot 某个网页或网站已永久移动 ...

  3. 更简洁的 CSS 清理浮动方式

    CSS清理浮动有很多种方式,像使用 br 标签自带的 clear 属,使用元素的 overflow,使用空标签来设置 clear:both 等等.但考虑到兼容问题和语义化的问题,一般我们都会使用如下代 ...

  4. C#2.0 特性

    泛型 迭代器 分布类 可空类型 匿名方法 命名空间别名限定符 静态类 外部程序程序集别名 属性访问器可访问性 委托中的协变和逆变 如何声明.实例化.使用委托 固定大小的缓冲区 友元程序集 内联警告控制 ...

  5. HDOJ 4389 X mod f(x)

    数位DP........ X mod f(x) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. SpringMVC 表单标签

    引入标签库 <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" ...

  7. JAVA操作ORACLE数据库的存储过程

    一.任务提出 JAVA操作oracle11g存储过程实验需要完成以下几个实例: 1.调用没有返回参数的过程(插入记录.更新记录) 2.有返回参数的过程 3.返回列表的过程 4.返回带分页的列表的过程. ...

  8. C++多线程的几个重要方法解析CreateEvent / SetEvent /ResetEvent/ 等

    1.CreateEvent 是创建windows事件的意思,作用主要用在判断线程退出,程锁定方面. 函功能描述:创建或打开一个命名的或无名的事件对象. HANDLE m_hExit; m_hExit= ...

  9. Java开源安全框架之Apache Shiro

    APACHE SHIRO安全框架 1      背景 Shiro项目始于2003年初,当时它叫JSecurity项目,当时对于Java应用开发人员没有太多的安全替代方案,始终被一个叫JAAS(Java ...

  10. Android学习笔记(十四)——自定义广播

    //此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 我们除了可以通过广播接收器来接收系统广播, 还可以在应用程序中发送自定义的广播.下面我们来分别试一试发送自定义 ...