jeecg 图片上传
1.页面上传标签
<t:formvalid formid="addImageForm" dialog="true" usePlugin="password"layout="table" tiptype="1" action="itemController.do?doAddImage" ><input name="itemId" value="${itemId}" type="hidden"><input id="fileupload" type="file" name="files[]" accept="image/*" data-url="fileUploadController.do?upload" multiple><div id="uploaded-files"></div>
</t:formvalid>
2.上传后的操作
1 public LinkedList<FileMeta>upload(MultipartHttpServletRequest request, HttpServletResponse response) {2 //1. build an iterator 3 Iterator<String> itr =request.getFileNames();4 MultipartFile mpf = null;5 String path="";//上传文件的路径 6 String fileName="";//文件名 7 String newFileName="";//新文件名 8 String savePath="";//文件保存全路径9 //2. get each file 10 while(itr.hasNext()) {11 12 //2.1 get next MultipartFile 13 mpf =request.getFile(itr.next());14 //System.out.println(mpf.getOriginalFilename() + " uploaded! " + files.size());15 16 //2.2 if files > 10 remove the first from the list 17 if (files.size() >= 10)18 files.pop();19 20 //2.3 create new fileMeta 21 fileMeta = newFileMeta();22 //fileMeta.setFileName(mpf.getOriginalFilename()); 23 fileMeta.setFileSize(mpf.getSize() / 1024 + " Kb");24 fileMeta.setFileType(mpf.getContentType());25 26 try{27 fileMeta.setBytes(mpf.getBytes());28 //String path ="upload/";29 //String realPath = request.getSession().getServletContext().getRealPath("/") + "/" + path ;//文件的硬盘真实路径30 //String savePath = realPath + mpf.getOriginalFilename();//文件保存全路径 31 fileName=mpf.getOriginalFilename();32 path=ResourceUtil.getConfigByName("tempPath");33 newFileName =NumberMaker.createFileName(fileName);34 savePath = path + newFileName; //文件保存全路径35 //copy file to local disk (make sure the path "e.g. D:/temp/files" exists) 36 FileCopyUtils.copy(mpf.getBytes(),newFile(savePath));37 fileMeta.setFileName(newFileName);//将新的随机数文件名赋给文件名属性 38 } catch(IOException e) {39 e.printStackTrace();40 }41 //2.4 add to files 42 files.add(fileMeta);43 44 }45 46 //result will be like this47 //[{"fileName":"app_engine-85x77.png","fileSize":"8 Kb","fileType":"image/png"},...] 48 returnfiles;49 }
3.选择图片后获得选择的图片名称
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
$( '#fileupload' ).fileupload({
maxChunkSize: 2000000, // 最大2MB
dataType: 'json' ,
done: function (e, data) {
var cc = 0;
console.log( "in" );
$.each(data.result, function (index, file) {
console.log( "index:" +index);
$( "#uploaded-files" ).append(
$( "<input name='filename' type='hidden' />" ).val(file.fileName)
)
});
cc++;
}
|
4.引入js
<script src="plug-in/jquery-plugs/fileupload/js/vendor/jquery.ui.widget.js"></script> <script src="plug-in/jquery-plugs/fileupload/js/jquery.iframe-transport.js"></script> <script src="plug-in/jquery-plugs/fileupload/js/jquery.fileupload.js"></script>
5.提交表单
publicAjaxJson doAddImage(ItemImageEntity image, HttpServletRequest request) {String itemId=request.getParameter("itemId");String fileName=request.getParameter("filename");String path="";String imagePath="";AjaxJson j= newAjaxJson();String message= "添加成功";try{path=ResourceUtil.getConfigByName("uploadPath");String tempPath=ResourceUtil.getConfigByName("tempPath");String oldPath= tempPath + fileName;//获取temp文件下的指定文件路径String newPath = path + fileName;//新目录File filein=newFile(oldPath);File fileout=newFile(newPath);//文件拷贝到指定硬盘目录 FileCopyUtils.copy(filein, fileout);//savePath = path + newFileName;//文件保存全路径imagePath="commonController.do?viewImg&imgUrl="+fileName;ItemEntity item=systemService.getEntity(ItemEntity.class, itemId);itemService.addImage(item, fileName, fileName,imagePath);systemService.addLog("图片名【"+image.getName()+"】"+message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);}catch(Exception e) {e.printStackTrace();message= "图片添加失败";systemService.addLog("图片名【"+image.getName()+"】"+e.getMessage(), Globals.Log_Type_INSERT, Globals.Log_Leavel_ERROR);throw newBusinessException(e.getMessage());}j.setMsg(message);returnj;}
jeecg 图片上传相关推荐
- jeecg uedit 自定义图片上传路径
jeecg uedit 图片上传配置自定义物理路径,简单描述:我们知道 jeecg 中使用的 uedit 默认图片上传路径为 "当前项目\plug-in\ueditor\jsp\upload ...
- uni-app 图片上传七牛云
前台uni-app+colorUi 后台jeecgboot 思路 用colorui能实现效果,但是路径还是指向本地 用七牛云,先上传到七牛云,返回路径并且指向它 后台去获取七牛token并且返回(最后 ...
- html显示数据库图片django,django将图片上传数据库后在前端显式的方法
1.使用ImageField先安装pillow模块 pip install pillow 2.在app的models中设置 class Image(models.Model): pic_name=mo ...
- yii2框架原生的结合框架使用的图片上传
首先我们要从model层开始写起,主要是为了创建验证规则,还有图片上传的路径以及图片的命名规则(UploadForm.php) 接下来我们要在控制器层写好业务逻辑,就是什么情况下直接在调用model层 ...
- java flex 图片上传_flex上传图片到java服务器
今天弄flex上传图片到java,现在弄成功,中间也经常一点小波折,现记录一下.重点在java侧的实现. flex侧:文件上载到在url参数中传递的URL.该URL必须是配置为接受上载的服务器脚本.F ...
- js表单提交,支持图片上传,包含后端php代码
微信小程序开发交流qq群 581478349 承接微信小程序开发.扫码加微信. <html><head><meta http-equiv="Conte ...
- ckeditor finder php,CKEDITOR CKFINDER的图片上传配置(C#/asp.net/php)
CKEDITOR+CKFINDER的图片上传配置(C#/asp教程.net/php教程) php keditor的代码全部重写,但里面没有了上传功能,只是一个纯粹的文件在线编辑器,如果需要上传图片,还 ...
- 图片上传(加水印、缩略图、远程保存)的简单例子
图片上传(加水印.缩略图.远程保存)的简单例子(应用于51aspx.com) 该源码下载地址:http://51aspx.com/CV/ImageUpload 今天看到xiongeee发的文章使用使用 ...
- 使用summernote实现复制图片即可实现图片上传
个人资源与分享网站:http://xiaocaoshare.com/ 1.页面结构 <script src="../statics/js/plugins/summernote/summ ...
最新文章
- shell学习之常用命令总结
- Spring.NET企业架构实践之 JQuery + FlexiGrid + ASP.NET MVC + NVelocity + WCF + LINQ + NHibernate 综合应用...
- 使用pyinstaller打包python_使用pyinstaller打包Python项目,python
- java 文件上传 配置_SpringMVCMultipartFilefile文件上传及参数接收
- Linux中的MAN命令
- jQuery 学习笔记 事件委派
- 一张图让你搞懂DES与RSA混合加密技术
- 软件安装及软件包管理
- 宜普电源转换公司(EPC)于2018年WiPDA宽能隙功率器件及应用论坛与工程师作技术交流
- tsmaster中文版(M3U8下载器)
- Python分析与处理---利用Python进行学生成绩分析
- 计算机毕业设计Java大学生第二课堂(源码+系统+mysql数据库+lw文档)
- 数据恢复国赛经验与方法分享(电子产品芯片级检测维修与数据恢复赛项)
- mysql查询排名名次
- java随机中文名_Java随机产生中文昵称
- 迷你图书管理器1.2 - 面向对象+集合
- 寺库拟私有化:报价较发行价缩水75%,趣店为第一大股东
- 现代计算机理论模型与工作方式
- php将excel数据导入mysql表中_利用php将xls表格数据以原生方式快速导入mysql
- Exception in thread “main“java.lang.NoClassDefFoundError:org/apache/HBaseConfiguration