最新亚洲精品福利在线,欧美一区二区三区大片,久久91无码一区二区三区,色哟哟免费观看视频入口,美女裸露双奶头屁股无裸体

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

時(shí)間:2020-07-16 22:26:53 類(lèi)型:JAVA
字號(hào):    

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());
    }
}


<