testMaven/src/com/neusoft/controller/UeditorController.java

(完整代码) 2KB

package com.neusoft.controller;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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

import com.neusoft.utils.UUIDUtils;

@Controller
@RequestMapping("/ueditor")
public class UeditorController {
	
	
	  
	  @ResponseBody  
	@RequestMapping(value = "/saveFile")  
    public Map<String, Object> saveFile(@RequestParam(value = "upfile", required = false) MultipartFile file,HttpServletRequest request, Model model) throws IllegalStateException, IOException {  
		  Map<String, Object> params = new HashMap<String, Object>();  
    	  System.out.println("开始");  
          long  startTime=System.currentTimeMillis();
          System.out.println("fileName:"+file.getOriginalFilename());
          String n = UUIDUtils.create();
          String path="D:/my/ueditor/"+n+file.getOriginalFilename();
          System.out.println("===================================================");
           System.out.println(path);
          File newFile=new File(path);
          //通过CommonsMultipartFile的方法直接写文件(注意这个时候)
          file.transferTo(newFile);
          String visitUrl = "/ueditor/"; 
          visitUrl = visitUrl.concat(n+file.getOriginalFilename());
          long  endTime=System.currentTimeMillis();
          System.out.println("方法二的运行时间:"+String.valueOf(endTime-startTime)+"ms");
         System.out.println("*********************************************************");
         System.out.println("*********************************************************");
         params.put("state", "SUCCESS");  
         params.put("url", visitUrl);  
         params.put("size", file.getSize());  
         params.put("original", file.getOriginalFilename());  
         params.put("type", file.getContentType());  
         return params;  
    }  
    
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。