项目需求:集成bootstrap + layui + java(MultipartFile) 实现 文件上传
js代码(可根据需要自行改成js或html页面代码):
var g = '<button type="button" class="layui-btn demoMore" title="上传文件"
lay-data="{url: \'/dl_manager/dlManager/uploadFile?id=' + row.id + '\',
accept: \'file\'}" >上传</button>';
layui 上传接口绑定
layui.use('upload', function () {
var upload = layui.upload;
//执行实例
var uploadInst = upload.render({
elem: '.demoMore', //绑定元素
//url: '/agentkey/agentKey/uploadOpenSSl', //上传接口
size: 1000,
accept: 'file',
size:'204800', //kb
before: function(){
console.log('接口地址:'+ this.url, this.item, {tips: 1});
},
/* done: function (r) {
//layer.msg(r.msg);
if(r.code == 0){
parent.layer.msg(data.msg);
}
// app.getData().code;
}, */
done: function(res, index, upload){
var item = this.item;
console.log(item); //获取当前触发上传的元素,layui 2.1.0 新增
reLoad();
},
error: function (r) {
//layer.msg(r.msg);
}
});
});
layui官方文档:
http://www.layui.com/demo/laydate.html
java 后台文件上传代码:
http://blog.csdn.net/z1729734271/article/details/79026295