以唯一約束爲例:
try {
flag = operateMenuMapper.insert(po);
} catch (Exception e) {
Throwable cause = e.getCause();
if(cause instanceof java.sql.SQLIntegrityConstraintViolationException){
log.info("title 字段違反唯一約束條件");
return new Result(1,0,"添加的菜單已存在,請勿重複添加!",null);
}
e.printStackTrace();
}