有时我们使用SSM框架时,会出现400的错误和这样的The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).页面显示,这是有可能我们创建对象POJO时所使用的类型不对,例如日期的类型是java.util.Date,而不是java.util.sql.
还有就是从页面传参进数据库时,如果有日期的参数,要对它先进行日期的转换,否则也会报400的错误,有个转变函数是:
//此方法用于日期的转换,如果未加,当页面日期格式转换错误,将报400错误,实际是因为此方法
public void initBinder(WebDataBinder binder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}