transferto()方法,是springmvc封装的方法,用于图片上传时,把内存中图片写入磁盘

  1. //上传图片  
  2.                 //1图片存储的路径  
  3.                 String pic_path="";  
  4.                 //2原名称  
  5.                 String originalFilename = items_pic.getOriginalFilename();  
  6.                 //3新名称(uuid随机数加上后缀名)  
  7.                 String newfileName=UUID.randomUUID()+originalFilename.substring(originalFilename.lastIndexOf("."));  
  8.                  //新的图片  
  9.                 File newfile=new File(pic_path+newfileName);  
  10.                 //把内存图片写入磁盘中  
  11.                 items_pic.transferTo(newfile);  
  12.                 //把新的图片写入到对象中,方便数据库中更新  
  13.                 itemsCustom.setPic(newfileName);  
  14.             // 调用service更新商品信息,页面需要将商品信息传到此方法  
  15.             itemsService.updateItems(id, itemsCustom);  

猜你喜欢

转载自blog.csdn.net/u012960049/article/details/79758130