@RequestMapping("/testRequestParamNoAnnotation")
public String testRequestParamNoAnnotation(String name){
return name + ",testRequestParam success.";
}
/**
* 由于@RequestParam 中的定义 boolean required() default true;
* 默认 required 是必须的
* 如果直接写成@RequestParam String name,访问的时候不加name参数的话,会请求报错: [org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'name' is not present]
* 很明显它说你必须要给定name参数
*
* produces="text/plain;charset=UTF-8"解决中文乱码
* @param name
* @return
*/
@RequestMapping(path="/testRequestParamWithAnnotation",produces="text/plain;charset=UTF-8")
public String testRequestParamWithAnnotation(@RequestParam(required = false) String name){
return name + ",testRequestParamWithAnnotation success.";
}