zoukankan      html  css  js  c++  java
  • Spring MVC 上传文件---代码实现

    package cn.kgc.updatefile;

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

    import javax.servlet.http.HttpServletRequest;
    import java.io.File;
    import java.io.IOException;
    import java.util.UUID;

    @Controller
    @RequestMapping("/user")
    public class UpdateFile {

    @RequestMapping("/uploadTest")
    public String uploadTest(String username, MultipartFile upload, HttpServletRequest request){
    String realPath = request.getSession().getServletContext().getRealPath("/updateTest");
    File file = new File(realPath);
    if(!file.exists()){
    file.mkdirs();
    }
    String uuidName = UUID.randomUUID().toString().replace("-", "");
    String originalFilename = upload.getOriginalFilename();
    System.out.println(originalFilename);

    String fileName=uuidName+originalFilename;
    System.out.println(fileName);

    try {
    upload.transferTo(new File(file,fileName));
    } catch (IOException e) {
    e.printStackTrace();
    }
    return "show";
    }
    }
  • 相关阅读:
    03.通过商品课程初心商品信息
    04.支付宝支付流程
    02.创建商品(表)应用(App)
    01.商品模块表结构
    七牛云上传视频
    Django之序列化器
    Django之抽象基类
    权限系统
    python实现简单工厂模式
    01.git基本操作
  • 原文地址:https://www.cnblogs.com/geng-geng1997/p/11358925.html
Copyright © 2011-2022 走看看