我用弹簧,所以我们通过
org.springframework.dao.DataIntegrityViolationException
try { ao_history_repository.save(new AoHistory(..));} catch (DataIntegrityViolationException e) { System.out.println("history already exist");}但是就像@KevinGuancheDarias提到的那样:
请注意,虽然这可行。 我建议通过在save之前发出findBy来解决该问题
,因为这很麻烦,我认为不保证它将在将来的版本中使用,甚至可能在没有通知的情况下中断。



