@RequestMapping(value = “/test”) public String test( @RequestParam(value = “profit”,required = false,defaultValue = “0”) int profit){ System.out.println(“profit:”+profit); return “success”; } 第一种处理方式(如上图):defaultValue请求参数的默认值,一般和 required = false 一起使用
第二种处理方式:接收的参数如果是null的话,int就要改为Integer,Integer默认值为null
@RequestMapping(value = “/test”) public String test(@RequestParam( @RequestParam(value = “profit”,required = false) Integer profit){ System.out.println(“profit:”+profit); return “success”; }