文件类型转换错误cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

文件类型转换错误

原文请移步

 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest)(request);

空文件上传会出现类型转换错误
做一步处理

MultipartHttpServletRequest multipartRequest =null;
if (request instanceof MultipartHttpServletRequest) {
multipartRequest = (MultipartHttpServletRequest)(request);
}

先判断httpRequest 是否含有文件类型 ,若含文件,则将httpRequest 转换为MultipartHttpServletRequest类型。

posted @ 2020-11-30 11:49  无与伦比的傻  阅读(2315)  评论(0编辑  收藏  举报