2018-11-13
在表單提交時有時候會提示 Validation failed for object=’user’. Error count: 1,其中user是表的名字,Error count是對應數據庫中出錯的第幾個字段,解決方法有兩種:
第一種
把表單中需要提交的數據按數據庫中字段的順序提交
第二種
在表單對應的controller中添加BindingResult
第二種:
//員工添加 @PostMapping("/emp") public String addEmp(Employee employee, BindingResult bindingResult){ //redirect重定向到一個地址 //forward表示轉發到一個地址/代表當前項目下路徑下的emps System.out.print(employee); // employeeDao.save(employee); return "redirect:/emps"; }