我到底在哪里使用控制器类的方法处理数据库异常。我正在使用休眠来管理数据库 我遇到的情况是我在数据库中输入了xyz@gmail.com。现在,当我使用数据库中的主键相同的电子邮件地址进行注册时,它将显示DataIntegrityViolation的默认500错误页面。 / p>
//我正在这样做,但这无济于事
@RequestMapping(value = "/signup", method = RequestMethod.POST)
public ModelAndView signUp(@Valid @ModelAttribute("TemporaryUser") TemporaryUser user,
BindingResult result) {
if (result.hasErrors()) {
ModelAndView model = new ModelAndView("index");
model.addObject("error", "An error occured, try again!");
return model;
}
String checkEmail = user.getEmail();
TemporaryUser temporaryUser;
temporaryUser = temporaryUserService.findByEmail(checkEmail);
if (temporaryUser != null) {
ModelAndView model = new ModelAndView("index");
model.addObject("message",
"We already have an entry with this email address , try with other email address");
return model;
}