如何获取前台传来的file类型文件
利用@RequestParam(value = “传来的文件名”,required = false)MultipartFile multipartFile来解析;
这样操作会破坏spring的自动封装实体类,不能直接一个user类来接收前台的所有传参了;
通过multipartFile.getInputStream()方法将文件转换成InputStream流;
@RequestMapping(value = "/insert",method = RequestMethod.POST)
@ResponseBody
public ModelAndView insert(@RequestParam(value = "bookimg",required = false)MultipartFile multipartFile,
HttpServletRequest request,
HttpServletResponse response,
String bookname,
String bookintro,
String booktype,
String bookcon,
String bookwriter, HttpSession session, ModelAndView mv)throws IllegalStateException, IOException
mvc.xml配置
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"/>
<property name="maxUploadSize" value="512895771"/>
</bean>