图片上传
来源:互联网 发布:色诺芬经济金融数据库 编辑:程序博客网 时间:2024/05/22 02:29
新手,图片上传功能的完整方法链
control层:
@RequestMapping("uploadImage.do") public String importExcel(@RequestParam MultipartFile uploadfile, HttpServletRequest request, HttpServletResponse response,String id) { //获取输入的文件名 String fileName = uploadfile.getOriginalFilename(); if (StringUtils.isEmpty(fileName)) { System.out.println("未上传文件名为空"); } //获取路径 String tempPath = request.getSession().getServletContext().getRealPath("/") + "upload\\ysdwanimal"; File dir = new File(tempPath); if (!tempPath.endsWith(File.separator)) { tempPath = tempPath + File.separator; } if (!dir.exists()) { dir.mkdirs(); } System.out.println(tempPath+fileName); //检查是否重复上传 YsdwAnimal ysdwAnimal = ysdwAnimalService.getEntryById(id); if(ysdwAnimal == null){ return "uploadfail"; } //重写数据库储存路径 String lj=request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/whzhly/upload/ysdwanimal/"+id+".jpg"; //保存路径 ysdwAnimal.setLujing(lj); ysdwAnimalService.saveOrUpdateYsdwAnimal(ysdwAnimal); //获取完整的图片名 String newFile = tempPath + id+".jpg"; File file = new File(newFile); //图片复制到指定文件夹中,实现路径 try { FileCopyUtils.copy(uploadfile.getBytes(), file); System.out.println("成功上传"); } catch (IOException e) { e.printStackTrace(); return "uploadfail"; } return "uploadsuccess"; }}
0 0
- 图片上传
- 上传图片
- 上传图片
- 上传图片
- 上传图片
- 上传图片
- 图片上传
- 图片上传
- 上传图片
- 上传图片
- 图片上传
- 图片上传
- 图片上传
- 图片上传
- 上传图片
- 上传图片
- 上传图片
- 图片上传
- Qt自适应大小显示图片,添加菜单
- java静态代理和动态代理
- matplotlib画图内存爆表
- [DPDK编程手册]5Mempool库
- hdoj杭电问题分类
- 图片上传
- Mat属性type,depth,step
- eclipse编辑默认的jsp文件
- 内部类
- Java基础之多线程
- 【SSH网上商城项目实战22】获取银行图标以及支付页面的显示
- HDU1548 A strange lift
- FFmpeg + SoundTouch实现音频的变调变速
- fPopover.js V1.0.0