老师在更新店铺信息时为啥报内部错误呢?更新的信息也可以更新到数据库
来源:6-4 店铺信息编辑之前端实现
qq_小霸王的男人_0
2019-06-03
Written [{msg=系统内部错误------3, success=false}] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@52933fa2]
```这是报错的
```下面时更新店铺的代码
@RequestMapping(value="/updateshop",method=RequestMethod.POST)
@ResponseBody
private Map<String, Object> updateShop(HttpServletRequest request) {
Map<String,Object> map=new HashMap<String, Object>();
if(!KaptchaUtil.determineKaptcha(request)) {
map.put("success",false);
map.put("msg","你输入的验证码错误!");
return map;
}
//利用jackson-databind组件完成相应参数转化,图片和店铺信息
String shopStr = HttpServletRequestUtil.getString(request,"shop");
ObjectMapper mapper=new ObjectMapper();
Shop shop=new Shop();
try {
shop = mapper.readValue(shopStr, Shop.class);
} catch (Exception e) {
map.put("success",false);
map.put("msg",e.getMessage()+"------1");
return map;
}
CommonsMultipartFile shopImg=null;
//获取 文件上传内容CommonsMultipartResolver
CommonsMultipartResolver commonsMultipartResolver=new CommonsMultipartResolver(
request.getSession().getServletContext());
if(commonsMultipartResolver.isMultipart(request)) {//判断request里面有没有要上传的文件流
MultipartHttpServletRequest multipartHttpServletRequest=(MultipartHttpServletRequest)request;
shopImg=(CommonsMultipartFile)multipartHttpServletRequest.getFile("shopImg");
}else {
map.put("success",false);
map.put("msg","上传文件过程中出现错误!");
return map;
}
//修改店铺信息
if(shop!=null&&shop.getShopId()!=null) {
ImageHolder thumbnail=new ImageHolder();
ShopExecution se;
try {
if(shopImg==null) {
se=shopService.updateShop(shop,null);
}else {
thumbnail.setImage(shopImg.getInputStream());
thumbnail.setImageName(shopImg.getOriginalFilename().toString());
se=shopService.updateShop(shop,thumbnail);
}
if(se.getState()==ShopStateEnum.SUCCESS.getState()) {
map.put("success",true);
}else {
map.put("success",false);
map.put("msg",se.getStateInfo()+"------3");
return map;
}
} catch (IOException e) {
map.put("success",false);
map.put("msg","文件错误!");
return map;
}
}else {
map.put("success",false);
map.put("msg","请输入商铺注册信息!");
return map;
}
return map;
}
写回答
1回答
-
翔仔
2019-06-04
同学好,直接贴代码对解决问题没有太大帮助,编程不要黑盒哈,不要只对比代码,需要学会调试,其实这个问题,调试一下,看看究竟是哪个位置抛的错,才能具体去定位问题,甚至可以看到错误后,根据异常信息百度就能解决问题了,如何调试可以花几分钟学习下,这个对以后的工作很有帮助
https://jingyan.baidu.com/article/647f0115d666b27f2148a8b1.html
并且你的错误是返回到前端才报错吗?如果是,可以检查下ajax的属性配置包括contentType这些是否与视频一致
022019-06-05
相似问题