public String doEdit( BrandVO brandVO,@RequestParam(value="pic")MultipartFile file) throws IllegalStateException, IOException{
//CurrentUser user = CurrentUser.getInstance();
if(brandVO.getBrandid()!=null){//修改
brandVO.setChangetime(new Date());//最后修改时间(取当前系统时间)
String oddname=brandVO.getBrandpic();
if(oddname!=null){
new File("F:/client/images/"+oddname).delete();//删除原先的图片
}
String orgname=file.getOriginalFilename();
String savename=UUID.randomUUID()+orgname.substring(orgname.lastIndexOf("."));//保存图片的名字唯一
String savepath="F:/client/images/"+savename;
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(savepath));//图片存放位置
file.transferTo(new File(savepath));
brandVO.setBrandpic(savename);
service.update(brandVO);
}else{//新增
brandVO.setCreatetime(new Date());//取创建时的时间
brandVO.setChangetime(new Date());//最后修改时间(取当前系统时间)
String orgname=file.getOriginalFilename();
String savename=UUID.randomUUID()+orgname.substring(orgname.lastIndexOf("."));//保存图片的名字唯一
String savepath="F:/client/images/"+savename;
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(savepath));//图片存放位置
file.transferTo(new File(savepath));
brandVO.setBrandpic(savename);
service.add(brandVO);
}
return "redirect:/brand/list.action";//跳转到列表页面
}
————————————————
版权声明:本文为CSDN博主「LYF01fang」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/polisa/java/article/details/76974196