java.lang.IllegalStateException: Optional int parameter 'id' is not present but cannot be translated

异常如下:

Caused by: java.lang.IllegalStateException: Optional int parameter 'id' is not present but cannot be translated into a null value due to being declared as a primitive type. Consider declaring it as object wrapper for the corresponding primitive type.
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.checkValue(HandlerMethodInvoker.java:750)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:518)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:355)
	at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
	... 38 common frames omitted

解决方法:

将controller层接收数据的int的类型改为将Integer

你可能感兴趣的:(java,springmvc)