package com.lovecoding.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadFileController {

    @PostMapping("/uploadFile")
    public String up(MultipartFile file){
        /**
         * 既然是 文件上传， 那么必须要给我文件
         * 文件在 springmvc框架内 肯定是  函数形参传递过来
         */
        File filePath = new File("C:/Users/lc/Desktop/" + file.getOriginalFilename() );
        try {
            file.transferTo( filePath );
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "/success.jsp";
    }

}
