spring封装对象,如果对象中有时间格式,会出现400错误。
解决方法Controller中第一个方法添加自定义类型转换器
@Controller
@RequestMapping("/log")
public class LogController {
LogService logService = new LogService();
//自定义类型转换器
@InitBinder
public void initBinder(HttpServletRequest request,ServletRequestDataBinder binder) throws Exception {
binder.registerCustomEditor(
Date.class,
new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"),true));
}
@RequestMapping("/getManageLog")
public ModelAndView getManageLog(ManageLogObj manageLogObj,HttpServletRequest request) throws Exception {
ModelAndView mv = new ModelAndView("/log/manage_log");
List<ManageLogObj> manageLogObj_list = logService.getManageLog(manageLogObj);
mv.addObject("manageLogObj_list",manageLogObj_list);
return mv;
}
}