0
点赞
收藏
分享

微信扫一扫

Jquery中使用ajax请求SSM后台时提示:org.springframework.http.converter.HttpMessageNotReadableException: Could no


场景

Jquery中使用ajax向SSM后台请求数据时提示:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Stream closed

Jquery中使用ajax请求SSM后台时提示:org.springframework.http.converter.HttpMessageNotReadableException: Could no_json

实现

出现这种错误是因为前段请求参数和后端接受参数不对应导致。

前端:

 

$.ajax({
             type: 'POST',
             url: formAction,
             cache: false,  //禁用缓存
             data:JSON.stringify({"guojiStrart":guojiStrart,"guojiEnd":guojiEnd}),
             contentType: "application/json",
             dataType: "json",
             success: function (result) {
                 debugger
                
             }
         });

后端错误代码:

@ResponseBody
 @RequestMapping("/validateIsGuoNeiAll")
 public Map<String, Object> validateIsGuoNeiAll(@RequestBody Map<String, Object>  param1,@RequestBody Map<String, Object>  param2){
  
  Map<String, Object> result = new HashMap<String, Object>();
  Object PrintId = param1.get("guojiStrart");
  return result;
  
  
 }

正确代码:

@ResponseBody
 @RequestMapping("/validateIsGuoNeiAll")
 public Map<String, Object> validateIsGuoNeiAll(@RequestBody Map<String, Object>  params){
  
  Map<String, Object> result = new HashMap<String, Object>();
  Object PrintId = params.get("guojiStrart");
  return result;
  
  
 }

接受用一个map接收即可。


 

举报

相关推荐

0 条评论