0
我想使用休眠驗證來驗證我的表單。顯示用於驗證的自定義消息
這是我的實體類:
@Entity
@Table(name = "Employee")
@Proxy(lazy = false)
public class Employee implements Serializable
{
private static final long serialVersionUID = 1L;
@Column(name="name")
@NotEmpty
private String name;
@Column(name="mobileNumber")
@NotNull
private Long mobileNumber;
@Column(name="email")
@Pattern(regexp="^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")
@NotEmpty
private String email;
}
這是我的控制器:
@RequestMapping(value= "/employee/add", method = RequestMethod.POST)
public String addEmployee(@ModelAttribute("employee") @Valid Employee emp,
BindingResult result, Model model)
{
//validator.validate(emp, result);
this.employeeService.addEditEmployee(emp);
return "redirect:/employees";
}
當我提交表單具有空值,我得到一個約束衝突異常,這是爲什麼?
請分享您的堆棧跟蹤檢查.. –