这里这样理解吗
来源:4-7 店铺注册功能之Controller层的实现(下)
qq_蓝骏毅_04076633
2019-12-17
//map集合定义一个返回值
Map<String,Object> modelMap = new HashMap<String,Object>();
//1.接收并转化相应的参数,包活店铺信息以及图片信息
String shopStr = HttpServlerRequestUtil.getString(request, “shopStr”);
//将json转换为Shop实例
ObjectMapper mapper = new ObjectMapper();
Shop shop = null;
try {
shop = mapper.readValue(shopStr, Shop.class);
} catch (Exception e) {
modelMap.put(“success”, false);
modelMap.put(“errMsg”, e.getMessage());
return modelMap;
}
//将请求中的文件流剥离出来,通过CommonsMultipartFile去接收
CommonsMultipartFile shopImg = null;
//文件上传解析器
CommonsMultipartResolver commonsMultipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
//判断是否有上传的文件流
// 判断 request 是否有文件上传,即多部分请求…
if(commonsMultipartResolver.isMultipart(request)) {
//如果需要转换,有的话需要将request转换成MultipartHttpServletRequest对象
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
shopImg=(CommonsMultipartFile) multipartHttpServletRequest.getFile(“shopImg”);
}else {
modelMap.put(“success”, false);
modelMap.put(“errMsg”, “上传文件不能为空”);
return modelMap;
}
1回答
-
纯情的慕哥
2019-12-17
没毛病,奥里给
232019-12-18
相似问题