示例:
@RequestMapping(value = "/passcomment",
method = RequestMethod.POST,
produces = {"application/json;charset=UTF-8"}
)
@ResponseBody
int passComment(@RequestParam("cityId") int cityId, @RequestParam("spotName")String spotName, @RequestParam("context")String context) {
logger.info("正在存储评论");
//判空处理
if(context==null||context.isEmpty()) return -1;
int result = -1;
result = recommendService.passComment(cityId,spotName,context);
if(result!=-1){
logger.info("存储成功");
}
else{
logger.info("存储失败");
}
return result;
}
@RequestParam注解的含义就是请求参数,在这里很明显是需要客户端请求时发送的参数,并且定义了发送的标识名。
如@RequestParam("cityId")表示前端在使用该POST方法时只要发送的参数有cityId,就可以自动填充。
@RequestParam("cityId",required = true)表示一定需要该参数,如果不声明required也是默认必须要传该参数,相反如果required = false说明是非必要参数。(有一个小问题:当参数类型为int时,如果不传该参数,可