提问者:小点点

不存在必需的字符串参数“userName”


我正在尝试从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”。

有人能帮帮我吗?


共1个答案

匿名用户

你需要改变你

data: '{
        "userName":    "local_student",
        "newPassword": "test1231",
        "guid":        "376ed5f7-a780-455e-8682-6b5cf45cff80"
       }'

data: {
        userName:    "local_student",
        newPassword: "test1231",
        guid:        "376ed5f7-a780-455e-8682-6b5cf45cff80"
      }

没有

  1. '{
  2. 之前
  3. "包装用户名等时