58 lines
2.0 KiB
Java
58 lines
2.0 KiB
Java
package com.zzc.web.upload;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedList;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.annotation.Scope;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.util.FileCopyUtils;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import com.zzc.core.common.controller.BaseController;
|
|
import com.zzc.demo.plugin.entity.test.FileMeta;
|
|
import com.zzc.web.system.service.SystemService;
|
|
|
|
@Scope("prototype")
|
|
@Controller
|
|
@RequestMapping("/filesUploadController")
|
|
public class FilesUploadController extends BaseController {
|
|
|
|
private static final Logger logger = Logger.getLogger(FilesUploadController.class);
|
|
|
|
|
|
@RequestMapping(params = "upload", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public String upload(MultipartHttpServletRequest request, HttpServletResponse response) {
|
|
|
|
Iterator<String> itr = request.getFileNames();
|
|
MultipartFile mpf = null;
|
|
String fileName = "";
|
|
while (itr.hasNext()) {
|
|
mpf = request.getFile(itr.next());
|
|
try {
|
|
String path ="upload/";
|
|
String realPath = request.getSession().getServletContext().getRealPath("/") + "/" + path ;// 文件的硬盘真实路径
|
|
String savePath = realPath + mpf.getOriginalFilename();// 文件保存全路径
|
|
fileName = mpf.getOriginalFilename();
|
|
FileCopyUtils.copy(mpf.getBytes(),new File(savePath));
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return fileName;
|
|
}
|
|
|
|
}
|