弹簧params
的注释不起作用。
@RequestMapping(value = "/login", method = RequestMethod.PUT)
public @ResponseBody ResponseMsg login(@RequestParam String userName, @RequestParam String password )
{
ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);
if(responseMsg.getStatus().equalsIgnoreCase("True"))
{
responseMsg = userService.login(userName, password);
}
return responseMsg;
}
我正在使用此函数获取put中的值,但它显示400 Bad Request。有什么帮助吗?
答案 0 :(得分:3)
正确的答案是这个......而且是对OQJF来说
@RequestMapping(value = "/login", method = RequestMethod.GET)
public @ResponseBody ResponseMsg login(@RequestHeader(value="username", required=false) String userName,
@RequestHeader(value="password", required=false) String password ) {
ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);
if(responseMsg.getStatus().equalsIgnoreCase("True"))
responseMsg = userService.login(userName, password);
return responseMsg;
}
答案 1 :(得分:1)
首先使用firebug查看您发送给控制器的参数。如果参数名称正确。我认为原因是使用@RequestParam注释的字段默认是必需的,这意味着从客户端发送的参数必须包含userName和passWord的参数,更改为:@RequestParam(value="username" required=false) String userName, @RequestParam(value="password" required=false) String password
并尝试它。 / p>
答案 2 :(得分:0)
我不确定你想在这个场景中使用帖子。但您可以尝试访问标题参数,如下所示:
@RequestMapping(value = "/login", method = RequestMethod.PUT)
public @ResponseBody ResponseMsg login(@RequestHeader("username") String userName, @RequestHeader("password") String password ) {
ResponseMsg responseMsg = CommonUtils.checkParam(userName, password);
if(responseMsg.getStatus().equalsIgnoreCase("True"))
responseMsg = userService.login(userName, password);
return responseMsg;
}