简单的一个小例子而已,测试了下9W多条数据导入如果不做批量插入很费时,后改为批量插入在6秒左右:
上传jsp页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <script type="text/javascript"> i = 1; j = 1; $(document).ready(function(){ $("#btn_add1").click(function(){ document.getElementById("newUpload1").innerHTML+='<div id="div_'+i+'"><input name="file" type="file" /><input type="button" value="删除" onclick="del_1('+i+')"/></div>'; i = i + 1; }); $("#btn_add2").click(function(){ document.getElementById("newUpload2").innerHTML+='<div id="div_'+j+'"><input name="file_'+j+'" type="file" /><input type="button" value="删除" onclick="del_2('+j+')"/></div>'; j = j + 1; }); }); function del_1(o){ document.getElementById("newUpload1").removeChild(document.getElementById("div_"+o)); } function del_2(o){ document.getElementById("newUpload2").removeChild(document.getElementById("div_"+o)); } </script> </head> <body> <h1>springMVC字节流输入上传文件</h1> <form name="userForm1" action="/file/upload" enctype="multipart/form-data" method="post"> <div id="newUpload1"> <input type="file" name="file"> </div> <input type="button" id="btn_add1" value="增加一行" > <input type="submit" value="上传" > </form> <br> <br> <hr align="left" width="60%" color="#FF0000" size="3"> <br> <br> <h1>springMVC包装类上传文件</h1> <form name="userForm2" action="/file/upload2" enctype="multipart/form-data" method="post""> <div id="newUpload2"> <input type="file" name="file"> </div> <input type="button" id="btn_add2" value="增加一行" > <input type="submit" value="上传" > </form> </body> </html>
action部分,每1000条执行一次
/** * 更新csv数据 * @return */ @RequestMapping("/updatePayFeeData") @ResponseBody public Map<String, String> updatePayFeeData(HttpServletRequest request,HttpServletResponse response){ Map<String,String> map = new HashMap<String, String>(); //创建一个通用的多部分解析器 CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request.getSession().getServletContext()); //判断 request 是否有文件上传,即多部分请求 int pre = (int) System.currentTimeMillis(); if(multipartResolver.isMultipart(request)){ //转换成多部分request MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest)request; //取得request中的所有文件名 Iterator<String> iter = multiRequest.getFileNames(); while(iter.hasNext()){ try { MultipartFile file = multiRequest.getFile(iter.next()); InputStream is=file.getInputStream(); CsvUtil test = new CsvUtil(is); List<List<String>> csvList = test.readCSVFile(); if (!csvList.isEmpty()) { // int resNum=payFeeService.deleteData(); payFeeService.deleteData(); // int j=csvList.size(); List<PayFeeEntity> feeEntitiesList=new ArrayList<PayFeeEntity>(); for (List<String> list : csvList) { PayFeeEntity payFeeEntity =new PayFeeEntity(); payFeeEntity.setYearMon(list.get(0)); payFeeEntity.setIdno(list.get(1)); payFeeEntity.setMonthPay(Integer.valueOf(list.get(2))); payFeeEntity.setTotlePayfee(Long.valueOf(list.get(3))); feeEntitiesList.add(payFeeEntity); if (feeEntitiesList.size()==1000) { // int resultNum=payFeeService.insertPayFee(payFeeEntity); int resultNum=payFeeService.addStudentPath(feeEntitiesList); feeEntitiesList.clear(); } } if (feeEntitiesList.size()>0) { // int resultNum=payFeeService.insertPayFee(payFeeEntity); int resultNum=payFeeService.addStudentPath(feeEntitiesList); feeEntitiesList.clear(); } int finaltime = (int) System.currentTimeMillis(); System.out.println(finaltime - pre); map.put("code",Constant.getCode(Constant.SUCCESS)); map.put("result","success"); return map; }else { map.put("code",Constant.getCode(Constant.EMP_FILE)); map.put("result","false"); return map; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); map.put("code",Constant.getCode(Constant.FILE_FAIL)); map.put("msg",e.getMessage()); map.put("result","fail"); return map; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); map.put("code",Constant.getCode(Constant.FILE_FAIL)); map.put("msg",e.getMessage()); map.put("result","fail"); return map; } } } map.put("code",Constant.getCode(Constant.FILE_FAIL)); map.put("result","fail"); return map; }
mapper.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <mapper namespace="com.thfund.dao.PayFeeEntityMapper"> <resultMap id="BaseResultMap" type="com.thfund.model.PayFeeEntity"> <id column="id" property="id" jdbcType="INTEGER" /> <result column="year_mon" property="yearMon" jdbcType="VARCHAR" /> <result column="idno" property="idno" jdbcType="VARCHAR" /> <result column="month_pay" property="monthPay" jdbcType="INTEGER" /> <result column="totle_payfee" property="totlePayfee" jdbcType="BIGINT" /> </resultMap> <sql id="Base_Column_List"> id, year_mon, idno, month_pay, totle_payfee </sql> <insert id="addStudentPath" parameterType="java.util.List"> insert into pay_fee_info(year_mon, idno, month_pay, totle_payfee) values <foreach collection="list" item="item" index="index" separator="," > (#{item.yearMon,jdbcType=VARCHAR},#{item.idno,jdbcType=VARCHAR},#{item.monthPay,jdbcType=INTEGER},#{item.totlePayfee,jdbcType=BIGINT}) </foreach> </insert> </mapper>
mapper.java
int addStudentPath(List<PayFeeEntity> payFeeList);
相关推荐
Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+MyBatis实现的学生信息管理系统源码,SSM+Vue的学生管理系统。 Java基于Spring+SpringMVC+...
Struts2+maven+spring+mybatis整合,并实现注册功能实例。
校社联社团管理系统(Spring MVC+Spring+Mybatis+Redis),用来记录进度,和保存文件,完成一定阶段都上传到小组仓库中。 校社联社团管理系统(Spring MVC+Spring+Mybatis+Redis),用来记录进度,和保存文件,完成...
SSM(spring+spring MVC+mybatis)开发学生信息后台管理系统,实现学生增删改查功能设计一个简单的学生信息管理系统,要求使用SSM框架技术整合实现,用户登录后能够通过Web页面添加、删除、修改和查询学生信息 ...
基于spring+spring mvc+mybatis框架整合实现超市货物管理系统(实现登入功能、mysql数据库的增删改查及分页显示)
使用环境:MyEclipse/Eclipse + Tomcat + MySQL。...使用技术:Spring MVC + Spring + MyBatis 或 JSP + Servlet + JavaBean + JDBC。 演示地址:https://ymjin.blog.csdn.net/article/details/120991940
完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统(RESTful API+redis).zip 完善的Spring+SpringMVC+Mybatis+easyUI后台管理系统...
maven构建项目,简单的struts2、spring、mybatis结构实现,页面展示用的easyui
《spring+mybatis 企业应用实战》源码、类库全资料
使用环境:MyEclipse/Eclipse + Tomcat + MySQL。 使用技术:Spring MVC + Spring + MyBatis / JSP + Servlet + JavaBean + JDBC。
使用环境:MyEclipse/Eclipse + Tomcat + MySQL。 使用技术:Spring MVC + Spring + MyBatis / JSP + Servlet + JavaBean + JDBC。
struts2+spring+mybatis框架,附带数据库建表,适合初学者搭建环境。
Struts+Spring+Mybatis+EasyUI(jQuery)注解案例。采用注解的方式跟踪代码依赖性,实现替代配置文件功能。里面包含了平时用的增删改查及分页,分页查询时用的是存储过程,提高了数据库的性能。代码简单、易懂。
比较实用的springMvc+spring+Mybatis 实战案例
毕设项目:基于spring+mybatis实现高并发秒杀系统,包含详细笔记 毕设项目:基于spring+mybatis实现高并发秒杀系统,包含详细笔记 毕设项目:基于spring+mybatis实现高并发秒杀系统,包含详细笔记 毕设项目:基于...
基于SpringMVC+Spring+MyBatis个人技术博客系统源码.zip 完整代码,可运行 项目描述 基于SSM实现的一个个人博客系统,适合初学SSM和个人博客制作的同学学习。有了这个源码,直接买了阿里云或腾讯服务器,就可以部署...
使用环境: MyEclipse/Eclipse + Tomcat + MySQL。...使用技术: Spring MVC + Spring + MyBatis 或 JSP + Servlet + JavaBean + JDBC。 效果:https://ymjin.blog.csdn.net/article/details/119986708
Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
spring+springmvc+mybatis搭建的一个酒店管理系统附带mysql数据库 spring+springmvc+mybatis搭建的一个酒店管理系统附带mysql数据库
SpringMvc Spring Mybatis Maven 注解方式