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")进行默认值绑定
发布了27 篇原创文章 · 获赞 6 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/l1161558158/article/details/99342132
今日推荐