• 大小: 13.84MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-06-15
  • 语言: 其他
  • 标签:

资源简介

本小demo是一个上传文件demo(包含图片压缩多图上传),文档上传,上传到本地,运行先去改存到本地的地址位置。

资源截图

代码片段和文件信息

package com.controller;

import java.io.File;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
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 com.utils.CommonUtil;

@Controller
public class FileAjaxRaRUploadController {

/**
 * 压缩图片
 * @param request
 * @return
 */
    @RequestMapping(“testajax“)
    public String loginForm(HttpServletRequest request){

        return “ajaxRaRuplod“;

    }

    @RequestMapping(value=“/ajaxRaRupload“method=RequestMethod.POST)
    public String upload(@RequestParam(“file“) MultipartFile file HttpServletRequest requestString picName){

        if (!file.isEmpty()) {
            String storePath= CommonUtil.getURL(“storePath“);//从配置文件读取存储路径

            String uuid = UUID.randomUUID().toString().replace(“-“ ““);
String picNewName = uuid + picName.substring(picName.lastIndexOf(“.“));
            
//如果目录不存在,创建目录
            File filepath = new File(storePath picName);

            if (!filepath.getParentFile().exists()) {

                filepath.getParentFile().mkdirs();//如果目录不存在,创建目录

            }
            try {
                file.transferTo(new File(storePath+File.separator+picNewName));//把文件写入目标文件地址

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return “success“;
    }
 }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        878  2017-05-31 19:53  upload\.classpath

     文件       1039  2017-08-23 16:35  upload\.project

     文件        567  2017-05-31 19:41  upload\.settings\.jsdtscope

     文件        364  2017-05-31 19:41  upload\.settings\org.eclipse.jdt.core.prefs

     文件        567  2017-08-23 16:35  upload\.settings\org.eclipse.wst.common.component

     文件        345  2017-05-31 19:41  upload\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2017-05-31 19:41  upload\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2017-05-31 19:41  upload\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       1241  2017-08-23 14:28  upload\build\classes\applicationContext-service.xml

     文件       2724  2017-08-23 17:50  upload\build\classes\com\controller\FileAjaxRaRUploadController.class

     文件       1545  2017-08-23 17:15  upload\build\classes\com\controller\FileUploadArrController.class

     文件       3233  2017-08-23 17:11  upload\build\classes\com\controller\FileUploadController.class

     文件       2318  2017-08-23 17:14  upload\build\classes\com\utils\CommonUtil.class

     文件        663  2017-06-02 16:04  upload\build\classes\log4j.properties

     文件         41  2017-08-23 17:09  upload\build\classes\pc.properties

     文件       1575  2017-08-23 15:11  upload\build\classes\springmvc.xml

     文件       1241  2017-08-23 14:28  upload\config\applicationContext-service.xml

     文件        663  2017-06-02 16:04  upload\config\log4j.properties

     文件       1575  2017-08-23 15:11  upload\config\springmvc.xml

     文件       1736  2017-08-23 17:50  upload\src\com\controller\FileAjaxRaRUploadController.java

     文件       1024  2017-08-23 17:15  upload\src\com\controller\FileUploadArrController.java

     文件       2176  2017-08-23 17:11  upload\src\com\controller\FileUploadController.java

     文件       1593  2017-08-23 17:14  upload\src\com\utils\CommonUtil.java

     文件         41  2017-08-23 17:09  upload\src\pc.properties

     文件      26755  2017-06-01 20:57  upload\WebContent\js\jquery.form.js

     文件      91342  2017-06-01 20:57  upload\WebContent\js\jquery.js

     文件      23117  2017-08-23 17:20  upload\WebContent\js\lrz.bundle.js

     文件         39  2017-05-31 19:41  upload\WebContent\meta-INF\MANIFEST.MF

     文件       1422  2017-08-23 17:41  upload\WebContent\WEB-INF\jsp\ajaxRaRuplod.jsp

     文件        361  2017-08-23 16:17  upload\WebContent\WEB-INF\jsp\success.jsp

............此处省略60个文件信息

评论

共有 条评论

相关资源