异常处理-DefaultHandlerExceptionResolver

工作中遇到springmvc框架定义的方法中使用了【@RequestBody】 这个注解

代码如下:

	@RequestMapping(value = "create", method = RequestMethod.POST)
	@ResponseBody
	public ResultData createOrder(@RequestBody PrintOrders printOrders, HttpServletRequest request) throws JsonGenerationException, JsonMappingException, IOException {
		Integer productId = printOrders.getProductId();
}

调用接口的时候发生异常

2018-05-07 10:55:59.323 [qtp983814036-76] WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver - Failed to bind request element: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "create"

明显说的是转换类型问题, 引起这个问题的原因是@RequestBody ,注解用于读取http请求的内容并通过httpMessageConverter接口将内容绑定到controller的方法参数上,由于我没传printorders的参数,所以转换类型失败。


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值