BootstrapFileupload⽂件上传1.在jsp中引⼊css与js⽂件,
  <link href="${ctx}/plugins/fileup/css/fileinput.css" media="all" rel="stylesheet" type="text/css"/>----css   <script type="text/javascript" src="${ctx}/plugins/fileup/js/fileinput.js"/>----js
  <script src="${ctx}/plugins/fileup/js/fileinput_locale_th.js" type="text/javascript"></script>----
inputtypefile样式  <script src="${ctx}/plugins/fileup/js/fileinput_locale_zh.js" type="text/javascript"></script>----字体2.在jsp中初始化⽂件上传控件:
$(document).ready(function(){
/* 输⼊框联想 */
new CommunitySelect('searchCommunityName','${ctx}');
$('#table').bootstrapTable({
method:'post'
});
$("#edit").on("dal", function(){
$(this).removeData("bs.modal");
});
//⽂件上传
$('#file-zh').fileinput({
language: 'zh',
maxFilesNum: 1,
maxFileSize: 5000,
uploadUrl: '${ctx}/mindex/importCityIndex.do', //请求的路径
showUpload: true,
showRemove: true,
uploadAsync: true,
showPreview : true,
showCancel : false,
allowedFileExtensions: ['xlsx', 'xls']    //限定⽂件的类型
});
});
$("#file-zh").on("fileuploaded", function(event, data, previewId, index) {
var result = sponse;
if (result.success) {
$("#uploadModal").modal("hide");
$('#table').bootstrapTable("refresh");
bootbox.alert(result.msg);
} else {
bootbox.alert(result.msg);
}
});
3.在jsp中主体部分添加弹出窗体
//上传的按钮
<a href="#uploadModal" class="btn bg-blue" data-toggle="modal" data-preview-file-type="lsx/xlsx"><i
class="fa fa-download"></i> 上传</a>
<div class="modal fade" id="uploadModal" tabindex="-1" role="basic" aria-hidden="true">
<form enctype="multipart/form-data" id="uploadForm" method="post">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true"></button>
<h4 class="modal-title">导⼊</h4>
<div class="modal-body">
<div class="form-group">
<input id="file-zh" name="xlsFile" type="file" multiple>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
4、在controller中添加handler
@RequestMapping("importCityIndex")
@ResponseBody
public AjaxJson importCommunity(@RequestParam("xlsFile") MultipartFile file) throws IOException{  //file  得到要上传⽂件的输⼊流对象
InputStream inputStream = InputStream();
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。