java.sql.SQLIntegrityConstraintViolationException春季启动

时间:2019-09-03 23:22:05

标签: java spring-boot

我如何处理此异常

这是针对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并显示为消息

1 个答案:

答案 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接口的对象)。

相关问题