springmvc数据绑定是一个很好的东西,在数据绑定的时候一定要主意Controller方法中的参数名和jsp页面里的参数名字是否一致或者按照绑定的规范来写,如果不一致,可能回报如下错误:
The request sent by the client was syntactically incorrect ().从字面上理解是:客户端发送的请求语法错误。实际就是springmvc无法实现数据绑定。
一般是发生在jsp提交,aciton不能自动转化数据类型的错误
例如,jsp页面有日期类型,提交给action,但是action不能把页面的日期数据格式自动转为后台需要的日期格式,所以会抛出以上错误。
/** * 转换绑定的日期格式 * * @param request * @param model * @return */ @InitBinder public void initBinder(WebDataBinder binder) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); dateFormat.setLenient(true); binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); }