RestTemplate和web的一些坑

使用RestTemplate進行get請求時不能直接使用路徑訪問,需要使用類似於這種的url

/user/login?username={username}&password={password}

使用原始類型作爲Controller的參數時,在發現沒有這個參數時,將會拋出一個錯誤,如下

Optional int parameter 'resTypeId' is 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.

解決的方法有兩種

  1. 使用包裝類型,這時候包裝類型的值爲null
  2. 使用@RequestParam(required=false,defaultValue="123")進行默認值綁定
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章