国产午夜色司机在线观看,亚洲国产小视频在线观看,国产精品毛片一级久久,欧美高清vivoe,国产指交视频一区之二区,中文字幕在线码一区,18成禁人视频免费网站,影视中文综合国产,在线观看特色大片免费视频,午夜激情成人在线

springboot+jpa接收實(shí)體及文件的上傳

時(shí)間:2020-07-16 22:26:53 類型:JAVA
字號:    

springboot+jpa接收實(shí)體及文件的上傳

@Controller
public class Student {
    @RequestMapping(value="/admin/student/add",method = RequestMethod.GET)
    public String add(){
        return "/admin/student/add";
    }
    @ResponseBody
    @RequestMapping(value="/admin/student/addsave", method = RequestMethod.POST)
    public void addsave(@RequestParam(value = "myfile") MultipartFile myfile, Students students){
        String pic = "";
        if (!myfile.isEmpty()) {
            String fileName = myfile.getOriginalFilename();  // 文件名
            String suffixName = fileName.substring(fileName.lastIndexOf("."));  // 后綴名
            String filePath = "F:/java/uploads/"; // 上傳后的路徑
            pic = UUID.randomUUID() + suffixName; // 新文件名
            File dest = new File(filePath + pic);
            if (!dest.getParentFile().exists()) {
                dest.getParentFile().mkdirs();
            }
            try {
                myfile.transferTo(dest);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        System.out.println(students.getNames());
    }
}


<