单文件上传
配置文件设置
@Component
public class MultipartConfig {
@Bean
public MultipartConfigElement multipartConfigElement(){
MultipartConfigFactory factory=new MultipartConfigFactory();
//设置文件上传大小
factory.setMaxFileSize("256KB");
//设置总上传文件总大小
factory.setMaxRequestSize("512KB");
//设置文件上传路径
factory.setLocation("D:/temp/");
return factory.createMultipartConfig();
}
}
单文件上传controller
@RequestMapping(value = "upload", method = RequestMethod.POST)
@ResponseBody
public String upload(@RequestParam("file") MultipartFile file , HttpSession session) {
if (!file.isEmpty()) {
try {
FileCopyUtils.copy(file.getBytes(), new File(uploadPath + file.getOriginalFilename()));
} catch (IOException e) {
e.printStackTra