这里这样理解吗

来源: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

没毛病,奥里给

2
3
翔仔
回复
纯情的慕哥
赞同学的热心支持,看注释这样理解是没问题的
2019-12-18
共3条回复

Java双版本(SSM到SpringBoot)校园商铺全栈开发

SSM商铺V1.0,解决毕设痛点;SpringBoot商铺V2.0,满足工作刚需

5113 学习 · 8144 问题

查看课程