*/ @RestController public class FileUploadController { @PostMapping("/upload") public void upload(@RequestParam MultipartFile file) throws IOException { BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(new File( file.getOriginalFilename()))); System.out.println(file.getName()); out.write(file.getBytes()); out.flush(); out.close(); } } @RequestMapping(value = "/updates.action") // public ModelAndView updateitem(Items items){ public String updateitem(QueryVo vo, MultipartFile pictureFile) throws Exception{ //保存图片到 String name = UUID.randomUUID().toString().replaceAll("-", ""); //jpg String ext = FilenameUtils.getExtension(pictureFile.getOriginalFilename()); pictureFile.transferTo(new File ("E:\\upload\\" + name + "." + ext)); vo.getItems().setPic("E:\\upload\\" + name + "." + ext); //修改 itemService.update(vo.getItems()); // ModelAndView mav = new ModelAndView(); // mav.setViewName("success"); return "redirect:/itemEdit.action?id=" + vo.getItems().getId(); // return "forward:/item/itemlist.action"; } import org.apache.commons.io.FilenameUtils; apache 提供io包
SpringMvc实现文件上传
最新推荐文章于 2024-11-09 11:25:35 发布