您的位置:首页 > 产品设计 > UI/UE

The request sent by the client was syntactically incorrect ()问题

2015-12-07 15:29 387 查看
这两天试着做web项目碰到不少问题,其中一个就是使用springmvc时提交一个请求,返回400如题所示的问题,网上搜了一下,多数回答都是以下两种:

1.请求表单中参数和controller中的接收参数不匹配。

2.必选参数没传。

3.int型参数传了null。

我的controller中接收方法如下:

@RequestMapping(value = "saveNote", method = RequestMethod.POST)
@RequiresPermissions(value = { "note_create", "note_edit" }, logical = Logical.OR)
public String save(NoteEntity noteEntity, HttpSession session) throws Exception {
if (noteEntity == null || noteEntity.getId() == null) {
noteEntity.setCreated(System.currentTimeMillis());
}
noteService.save(noteEntity);
session.setAttribute("message", SAVE_SUCCESS);
return "redirect:/admin/note/listNote";
}


调试请求参数,最后发现原来是NoteEntity中的某个id为long型,而前台页面提交请求时并没有给这个同名input赋值,这就导致了把null赋给基本数据类型的错误。最后的解决方案是改为Long封装类型。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: