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")进行默认值绑定
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章