Is it possible to have empty RequestParam values use the defaultValue?

后端 未结 5 1869
北海茫月
北海茫月 2020-11-30 20:15

if I have a a request mapping similar to the following:

@RequestMapping(value = \"/test\", method = RequestMethod.POST)
@ResponseBody
public void test(@Reque         


        
5条回答
  •  离开以前
    2020-11-30 21:08

    You can keep primitive type by setting default value, in the your case just add "required = false" property:

    @RequestParam(value = "i", required = false, defaultValue = "10") int i
    

    P.S. This page from Spring documentation might be useful: Annotation Type RequestParam

提交回复
热议问题