示例:
@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时,如果不传该参数,可

本文介绍了在SSM框架中使用@RequestParam注解处理POST请求的方法,强调了RequestParam的含义和required属性的重要性。同时,讲解了前端如何设置Content-Type为"application/x-www-form-urlencoded"来发送数据,特别是在微信小程序中需要注意的请求头设置,以确保正确传递包括中文字符在内的参数。
最低0.47元/天 解锁文章
2175

被折叠的 条评论
为什么被折叠?



