首页>代码>Spring Boot整合Freemarker实现文件上传项目实例>/springboot-uploading-files/src/main/java/com/hellokoding/uploadingfiles/UploadingController.java
package com.hellokoding.uploadingfiles;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

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

@Controller
public class UploadingController {
    public static final String uploadingDir = System.getProperty("user.dir") + "/uploadingDir/";

    @RequestMapping("/")
    public String uploading(Model model) {
        File file = new File(uploadingDir);
        model.addAttribute("files", file.listFiles());
        return "uploading";
    }

    @RequestMapping(value = "/", method = RequestMethod.POST)
    public String uploadingPost(@RequestParam("uploadingFiles") MultipartFile[] uploadingFiles) throws IOException {
        for(MultipartFile uploadedFile : uploadingFiles) {
            File file = new File(uploadingDir + uploadedFile.getOriginalFilename());
            uploadedFile.transferTo(file);
        }

        return "redirect:/";
    }
}
最近下载更多
小资李  LV13 2021年6月26日
mudingc木钉  LV30 2021年6月16日
chaoslaw  LV1 2021年5月27日
天险无涯  LV15 2021年4月12日
123456nty  LV37 2021年3月11日
1719863922  LV11 2020年12月9日
gangzi125  LV9 2020年11月13日
hulewang  LV7 2020年11月8日
最近浏览更多
ssh123  LV10 4月23日
zuidaima_ttt 2月23日
暂无贡献等级
哪里的完整版  LV7 2023年12月15日
张朕朕  LV3 2023年9月10日
西瓜哥哥  LV4 2023年8月3日
Rommel  LV27 2023年6月6日
月光skr  LV3 2023年4月16日
神龙摆尾无拘束  LV2 2023年3月17日
renjunyou  LV10 2023年3月6日
微信网友_6319582217965568  LV3 2023年2月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友