springMVC从上传的Excel文件中读取数据并写入数据库

页面效果:

一、编辑xls

数据方面我用了三条,两条手机号码正确的数据,一条手机号码错误的数据,结果应该是插入前面两条。

这里有个问题就是,手机在excel解析的时候会变成科学记数法的数值,如果保存的格式是String类型,就会出现解析报错,所以需要把手机的单元格设置成文本格式,设置单元格格式是不行的,具体的方式例如wps是进入数据-->分列中去做设置。

二、在spring的xml文件设置上传文件大小

<!-- 上传文件拦截,设置最大上传文件大小   10M=10*1024*1024(B)=10485760 bytes -->  
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
    <property name="maxUploadSize" value="10485760" />  
</bean>

三、html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="pragma" content="no-cache" />
		<base target="_self" />
		<title>新增</title> 
        //还需要导入easyUI,这里省略了
		<script type="text/javascript">
			$(document).ready(function(){
			//添加页面初始化需要往控件设置的值
				if('${flag?if_exists}'!=''){
			  		if('${flag?if_exists}'=='success'){
			  			messageAlert('提示',"保存成功!","success");
			  			//window.returnValue=true;
			  			window.location.href = "需要跳转的下一个页面的地址";
			  		}else{
			   			messageAlert('提示',"保存失败!","error");
			 		}
			 	}
			});
			
			function doSave(){
				var t = $('#saveForm').form('validate'); 	
 				if(t){
					document.getElementById('saveForm').submit();
				}
			}
		</script>
	</head>
	<body>
		<div class="">
			<div class="">
				<form id="saveForm" action="action路径" method="post" enctype="multipart/form-data">
					<table class="">
					  	<tr>
					  		<td class="gray" >上传需要导入的excel文件:<label class="requiredFlag">*</label></td>
					 		<td colspan="3">
								<input type="file" name="file" id="templetpath" class="easyui-validatebox" required="true" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, applicat
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值