@ResponseBody
@RequestMapping("/task/updateDefect")
public void updateDefect( HttpServletRequest request, HttpServletResponse response) throws IOException {JSONObject result = new JSONObject();
BufferedReader br;
StringBuilder sb = new StringBuilder("");
br = new BufferedReader(new InputStreamReader((ServletInputStream) request.getInputStream(), "utf-8"));
response.setContentType("text/plain;charset=UTF-8");
String temp;
while ((temp = br.readLine()) != null) {
sb.append(temp);
}
br.close();
if (sb != null) {
String msg = "error";//返回信息
int code = 1;
try {
//解析构造对象
JSONObject obj = JSONObject.parseObject(sb.toString());
if (obj != null) {
//获取key值为 defect 的值字符串
String defectstr=obj.getString("defect");
//defect 的值转为对象defect
Defect defect=JSONObject.parseObject(defectstr,Defect.class);
//获取imageList对象转为字符串
String imageListArray = obj.get("imageList").toString();
List<ImgBase64Entity> imageList = (List<ImgBase64Entity>) JSONArray.toList(JSONArray.fromObject(imageListArray), ImgBase64Entity.class);
String returnUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/upload/imgs/";//存储路径: //http://localhost:8080/SmartLine/upload/imgs/
String path = request.getSession().getServletContext().getRealPath("upload/imgs"); //文件存储位置
mainTenanceInterfaceService.updateDefect(returnUrl, path, defect, imageList);
msg = "success";//返回信息
code = 0;
}
} catch (Exception e) {
e.printStackTrace();
}
result.put("code", code);
result.put("message", msg);
result.put("result", "");
response.getOutputStream().write(result.toString().getBytes(), 0, result.toString().getBytes().length);
}
}
06-17
1923