前后端数据传输转换问题-java.util.LinkedHashMap cannot be cast to Entity
问题场景:项目前端使用json传输方式,后台接收后对象变成了LinkedHashMap
@ResponseBody
@RequestMapping(value = "/batchCharge.do",method ={RequestMethod.POST,RequestMethod.GET})
public Response batchCharge(@RequestBody List<PriceChargeDTO> priceplanChargeLst , HttpServletRequest request ){
Response resp = new Response() ;
}
return resp ;
}
前端参数
[{"additionId":494,"pricePlanId":5202466},{"additionId":497,"pricePlanId":5202466},{"additionId":494,"pricePlanId":5202475},{"additionId":497,"pricePlanId":5202475},{"additionId":494,"pricePlanId":5202473},{"additionId":497,"pricePlanId":5202473}]
原因分析:
项目是使用springmvc框架,json序列化用的是jackson,不支持List接受参数,可能是更换其他的json工具或者升级版本可以解决该问题。我们spring用的是4.0。
有个spring boot项目没有出现这个问题,springmvc是5.0
需要把参数改为数组形式[ ]
public Response batchCharge(@RequestBody priceplanChargeLst[] , HttpServletRequest request )