我如何处理此异常
这是针对JPA持久性的捕获错误
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并显示为消息
答案 0 :(得分:0)
在The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
部分中,仅重定向到catch
或其他端点,并显示一条消息,指出发生了问题。添加/admin/step1
毫无意义,因为ex.getCause()
返回一个getCause()
对象(准确地说是:实现Throwable
接口的对象)。