spring配置文件里加:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="defaultEncoding" value="utf-8"></property> <property name="maxUploadSize" value="10485760"></property> <property name="maxInMemorySize" value="40960"></property> </bean>
10485760是10MB
controller里大概这样写:
@RequestMapping(value = "/gds/excel/doImport", method = RequestMethod.POST) public String doImportExcel(@RequestParam("dataFile") CommonsMultipartFile file,Model model){ System.out.println(file.getOriginalFilename()); System.out.println(file.getSize()); System.out.println(file.getContentType()); try { file.transferTo(new File("d:\\aaaaaaa.bin")); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } model.addAttribute("msg", "ok"); return "gds/importExcelResult"; }
还真简单~~
|