我是ajax的新手。我找到了许多类似的答案,但我无法弄清楚为什么我的请求在语法上不正确。 这是我的代码: ajax代码:
@RequestMapping(value = "/remove-contacts", method=RequestMethod.POST)
@ResponseBody
public Long[] removeConnections(@RequestParam(value="userIds") String[] userIds, HttpServletRequest request) throws Exception {
//some code
return null;
}
Spring控制器:
/Users/me/my_teams_code/some_project/package/IWantThisClass.py
请帮我弄清楚我的错误。抱歉英文不好
答案 0 :(得分:0)
RequestParam不正确,您应该使用@RequestBody。 从高级别来看,您应该创建一个包含数组的POJO对象。
public class POJO {
private String[] userIds;
public POJO() {
}
/**
* @return the userIds
*/
public String[] getUserIds() {
return userIds;
}
/**
* @param userIds the userIds to set
*/
public void setUserIds(String[] userIds) {
this.userIds = userIds;
}
}
@RequestMapping(value = "/remove-contacts", method=RequestMethod.POST)
@ResponseBody
public Long[] removeConnections(@RequestBody POJO pojo, HttpServletRequest request) throws Exception {
//some code
return null;
}