例如如下代码中,理论上应该表示sex
可以不用传
@RequestMapping(value = "/register", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") public @ResponseBody String register(@RequestParam(required = true) String openid, @RequestParam(required = true) int platform, @RequestParam(required = true) String nickname, @RequestParam(required = true) String icon, @RequestParam(required = false) int sex, HttpServletRequest hsq) {
不传sex
的时候会报错
Caused by: java.lang.IllegalStateException: Optional int parameter 'sex' 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.
因为可选int
参数sex
存在,但是不能被转为null
值,因为其原始类型为int
?我的sex
参数并没有传啊,怎么提示存在。
建议使用包装类型代替基本类型。
👇 下面是我的公众号,高质量的博文我会第一时间同步到公众号,给个关注吧!