我正在尝试从java脚本控制台进行AJAX调用,如下所示
jQuery.ajax({
contentType: "application/json",
url: "/accountServices/resetPassword",
type: "POST",
data: '{
"userName":"local_student",
"newPassword":"test1231",
"guid":"376ed5f7-a780-455e-8682-6b5cf45cff80"
}'
});
我的控制方法是这样的。
@RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
public String resetPassword(@RequestParam("userName") String userName,
@RequestParam("newPassword") String newPassword,
@RequestParam("guid") String guid, Model uiModel,
HttpServletRequest request, final Locale locale)
throws MessagingException {
try {}
}
我得到了错误
不存在必需的字符串参数“userName”。
有人能帮帮我吗?
你需要改变你
data: '{
"userName": "local_student",
"newPassword": "test1231",
"guid": "376ed5f7-a780-455e-8682-6b5cf45cff80"
}'
到
data: {
userName: "local_student",
newPassword: "test1231",
guid: "376ed5f7-a780-455e-8682-6b5cf45cff80"
}
没有
'
在{
"包装用户名等时