//上传图片
//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.transferTo(newfile);
//把新的图片写入到对象中,方便数据库中更新
itemsCustom.setPic(newfileName);
// 调用service更新商品信息,页面需要将商品信息传到此方法
itemsService.updateItems(id, itemsCustom);
transferto()方法,是springmvc封装的方法,用于图片上传时,把内存中图片写入磁盘
最新推荐文章于 2024-06-16 08:50:28 发布