这句话的意思是客户端发送的请求语法错误,从而导致springmvc无法实现数据绑定。
而这种错误呢,大部分是由于参数格式不正确。
下面举一个例子来说明:
<form:form id="seller_changepassword_form" modelAttribute="accountmodel"
action="http://localhost:8080/Takout/views/html_jsp/test" method="get">
<input id="seller_new_password" style="margin-top:10px;margin-left:10px;height:30px;"type="text"autocomplete="off"value=""></input>
<button class="info_submit" id="seller_password_submit" type="submit">提交</button>
</form:form>
controller如下:
@RequestMapping(value ="views/html_jsp/test",produces = "application/json;charset=utf-8",method ={RequestMethod.GET})
public ModelAndView change_sellerpassword(HttpServletRequest request, @RequestParam("seller_new_password") int seller_new_password) {
ModelAndView mv = new ModelAndView();
mv.addObject("seller_new_password",seller_new_password);
}
从上面的form表单我们可以看到,input框输入新的密码,如果输入的是数字,那么将没有问题。
但是如果密码带有字符,如“123456789,.”这样的,那么因为controller中接收的参数声明的是int类型的
如下图
这样因为类型不匹配,提交之后就会出错。
因此这里必须注意一下,提交的数据与入参声明需要是同一个类型的,否则就报错。
另外,还有一点需要注意
上面的这个参数的名称必须和jsp页面提交的参数名字一样,否则将匹配不到。