失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java.util.LinkedHashMap cannot be cast to Entity

java.util.LinkedHashMap cannot be cast to Entity

时间:2019-07-04 03:50:51

相关推荐

java.util.LinkedHashMap cannot be cast to Entity

前后端数据传输转换问题-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 )

如果觉得《java.util.LinkedHashMap cannot be cast to Entity》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。