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.
解决的方法有两种
- 使用包装类型,这时候包装类型的值为null
- 使用@RequestParam(required=false,defaultValue=”123”)进行默认值绑定
还没有评论,来说两句吧...