使用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.
解決的方法有兩種
- 使用包裝類型,這時候包裝類型的值爲null
- 使用@RequestParam(required=false,defaultValue="123")進行默認值綁定