- //上传图片
- //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封装的方法,用于图片上传时,把内存中图片写入磁盘
猜你喜欢
转载自blog.csdn.net/u012960049/article/details/79758130
今日推荐
周排行