前端代码:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="views/lib/layui-v2.5.5/css/layui.css" media="all">
<link rel="stylesheet" href="views/css/layuimini.css?v=2.0.4.2" media="all">
<link rel="stylesheet" href="views/css/themes/default.css" media="all">
<link rel="stylesheet" href="views/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<script src="views/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="views/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script src="views/js/common.js" charset="utf-8"></script>
<!--[if lt IE 9]>
<script src="views/lib/export-word/excanvas-IE8.js"></script>
<script src="views/lib/export-word/jqueryWordExport-IE8.js"></script>
<script src="views/lib/other/html5.min.js"></script>
<script src="views/lib/other/respond.min.js"></script>
<![endif]-->
</head>
<body class="layui-layout-body">
<div class="layui-upload" align="center">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;" align="center">
<legend>请选择您要上传的Excel文件</legend>
</fieldset>
<div style="margin-top: 30px" align="center">
<button id="importData" name="file" class="layui-btn layui-btn-normal">导入</button>
</div>
</div>
</div>
<script>
layui.use(["element", "layer", "upload"], function () {
var layer = layui.layer;
layui.upload.render({
elem: "#importData",
url: '/upload',
size: '800',
accept: "file",
exts: 'xls|xlsx',
before: function () {
layer.load();
},
done: function (res) {
if (res.code==0) {
let index=layer.alert('上传成功!',function () {
layer.close(index);
});
} else layer.alert('失败',{icon:5});
layer.closeAll('loading');
}
});
});
</script>
</body>
</html>
</html>