//上传图片
//1图片存储的路径
String pic_path="";
//2原名称
String originalFilename = items_pic.getOriginalFilename();
//3新名称(uuid随机数加上后缀名)
String newfileName=UUID.randomUUID()+originalFilename.substring(originalFilename.lastIndexOf("."));
//新的图片
File newfile=new File(pic_path+newfileName);
//把内存图片写入磁盘中,items_pic为从前台获取的MultipartFile[]的元素对象,file为文件对象
items_pic.transferTo(newfile);
//把新的图片写入到对象中,方便数据库中更新
itemsCustom.setXXX(newfileName);
// 调用service更新方法
xxxService.updatexxx(id, itemsCustom);
transferto(),用于把图片上传到指定磁盘
最新推荐文章于 2024-06-16 08:50:28 发布
