![](/img/trans.png)
[英]java.sql.SQLIntegrityConstraintViolationException
[英]java.sql.SQLIntegrityConstraintViolationException Spring boot
我该如何处理这个例外
这是针对来自JPA持久性的catch错误
try {
if (platform.getPlatformId() == null) {
messageString = "inserted";
} else {
messageString = "updated";
}
Platform platf = platformServiceImpl.addOne(platform);
model.addAttribute("locations", locationServiceImpl.getAll());
//Date localDate = new Date();
//PlatformDetail newDetailPlatform = new PlatformDetail();
//newDetailPlatform.setLastUpdate(localDate);
//newDetailPlatform.setPlatform(platform);
//platformDetailServiceImpl.addOne(newDetailPlatform);
//redirectAttributes.addAttribute("platformId", platf.getPlatformId());
redirectAttributes.addFlashAttribute("success", messageString);
return "redirect:/admin/step1/" + platf.getPlatformId();
} catch (PersistenceException ex) {
redirectAttributes.addFlashAttribute("error", "dfdf");
return "redirect:/admin/step1/" + ex.getCause();
}
我希望发送带有重复键的RedirectParameter并显示为消息
在catch
部分中,仅向/admin/step1
或其他端点重定向,并显示一条消息,指出发生了问题。 添加ex.getCause()
毫无意义,因为getCause()
返回一个Throwable
对象(确切地说,是实现Throwable
接口的对象)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.