java数据库导入选择题_java实现Excel导入数据库,并返回导入信息

该博客介绍了一种使用Java实现的Excel文件导入数据库的方法,通过点击按钮触发AJAX请求,针对2007及2003版Excel进行不同处理。成功导入的数据会按题目类型展示,错误信息也会详细显示。
摘要由CSDN通过智能技术生成

$("#saveZipButton").on('click', function(){

var formData = new FormData();

var name = $("#articleImageFile").val();

var index = name.lastIndexOf(".");

var suffix = name.substring(index).toLowerCase();

formData.append("file",$("#articleImageFile")[0].files[0]);

formData.append("name",name);//这个地方可以传递多个参数

if(".xlsx" == suffix){

$("#uploadModal").modal('hide');

$.ajax({

url : "/excel/import_2007",

type : 'POST',

async : false,

data : formData,

// 告诉jQuery不要去处理发送的数据

processData : false,

// 告诉jQuery不要去设置Content-Type请求头

contentType : false,

success : function(res) {

//清空模态窗内容

$("#UploadSuccess").html("");

$("#UploadFail").html("");

//console.log(res);

if (res.map.statusCode==500){

layer.alert(res.message)

}else {

for (var index in res) {

if(res[index].map.statusCode == 200){  //上传正确信息

if(res[index].map.testList.stlx == "01"){

var html = "

\n" +

"true.png%5C%22 单选题: "+ res[index].map.testList.stmc +"
\n" +

"

"

}

if(res[index].map.testList.stlx == "02"){

var html = "

\n" +

"true.png%5C%22 多选题: "+ res[index].map.testList.stmc +"
\n" +

"

"

}

if(res[index].map.testList.stlx == "03"){

var html = "

\n" +

"true.png%5C%22 判断题: "+ res[index].map.testList.sttg +"
\n" +

"

"

}

if(res[index].map.testList.stlx == "04"){

var html = "

\n" +

"true.png%5C%22 填空题: "+ res[index].map.testList.sttg +"
\n" +

"

"

}

if(res[index].map.testList.stlx == "05"){

var html = "

\n" +

"true.png%5C%22 主观题: "+ res[index].map.testList.sttg +"
\n" +

"

"

}

$("#UploadSuccess").append(html);

}

if(res[index].map.statusCode == 500){  //上传错误信息

var rownuber = parseInt(res[index].map.row) + 1;

if(res[index].map.testList.stlx == "01"){

var html = "

\n" +

"false.png%5C%22 单选题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}else if(res[index].map.testList.stlx == "02"){

var html = "

\n" +

"false.png%5C%22 多选题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}else if(res[index].map.testList.stlx == "03"){

var html = "

\n" +

"false.png%5C%22 判断题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}else if(res[index].map.testList.stlx == "04"){

var html = "

\n" +

"false.png%5C%22 填空题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}else if(res[index].map.testList.stlx == "05"){

var html = "

\n" +

"false.png%5C%22 主观题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}else{

var html = "

\n" +

"false.png%5C%22 未知题(第"+ rownuber +"行): "+ res[index].map.errorMessage +"
\n" +

"

"

}

$("#UploadFail").append(html);

}

}

parent.layer.msg('正在校验文件内容,请稍候...', {shade: 0.3},function () {

layer.open({

type: 1,

title: ["上传结果", "color:#333333"], //不显示标题栏

closeBtn: false,

area: '600px;',

shade: 0.3,

id: 'LAY_layuipro', //设定一个id,防止重复弹出

btn: ['确认'],

btnAlign: 'a',

moveType: 1, //拖拽模式,0或者1

content: $("#uploadResult"),

yes: function(index,layero) {

$("#articleImageFile").val(""); //清空选择文件内容

search(pageNum,pageSize);

layer.close(index);

}

});

})

//错误信息窗结束

}

},

error:function (msg) {

layer.msg("程序发生错误,请联系技术人员!");

}

});

}else if(".xls" == suffix){

$("#uploadModal").modal('hide');

$.ajax({

url : "/excel/import_2003",

type : 'POST',

async : false,

dataType: "json",

data : formData,

// 告诉jQuery不要去处理发送的数据

processData : false,

// 告诉jQuery不要去设置Content-Type请求头

contentType : false,

success : function(res) {

//layer.msg('数据加载中,请稍后...',{shade: 0.3},function () {

//清空模态窗内容

$("#UploadSuccess").html("");

$("#UploadFail").html("");

//console.log(res);

if (res.map.statusCode==500){

layer.alert(res.message)

}else {

for (var index in res) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值