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

来源:互联网 发布:php 页面 空格 编辑:程序博客网 时间:2024/05/17 20:10
//上传图片//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);