UploadFileController.java 864 B

12345678910111213141516171819202122232425
  1. package com.controller;
  2. import org.springframework.stereotype.Controller;
  3. import org.springframework.web.bind.annotation.CookieValue;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.ResponseBody;
  6. import org.springframework.web.multipart.MultipartFile;
  7. import javax.servlet.http.HttpServletRequest;
  8. import java.io.File;
  9. import java.io.IOException;
  10. @Controller
  11. public class UploadFileController {
  12. // http://localhost:8083/template/upload_file.jsp
  13. @RequestMapping("/uploadFile")
  14. @ResponseBody
  15. public String uploadFile (String name, MultipartFile file1) throws IOException {
  16. System.out.println(12312);
  17. String originalFilename = file1.getOriginalFilename();
  18. file1.transferTo(new File("D:\\javaProject\\" + originalFilename));
  19. return "upload_file";
  20. }
  21. }