1. 程式人生 > >java.lang.IllegalStateException: Optional int parameter 'i' is not present but cannot be translated

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

開發中訪問方法時報

java.lang.IllegalStateException: Optional int parameter 'i' 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:742)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:511)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:348)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:436)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
方法程式碼:
	@RequestMapping("/app/store/index.htm")
	public void app_store_list(Double address_longitud,Double address_latitude,int i) {
          ...........
        }
		

從報錯資訊上看 是i不能賦值為null,於是查了下資料

大意是說 如果引數是非必須的,則會賦值為null,因此引數應該是一個object,它才能接受這個null值。

而上面程式碼引數page 的型別 為 int,它接受不了null值。


解決辦法就是將    int  轉換成包裝型別    integer


突發問題 ,記錄.