其中DataIntegrityViolationException可以用来处理保存的category有重复的异常 这个异常是Spring对数据库完整性约束的异常 public Category saveCategory(Category category) throws LibraryException ... { try...{ Category c=this.getCategoryDao().saveCategory(category); return c; } catch(DataIntegrityViolationException de)...{ throw LibraryException.getDuplicateCategoryNameException(); } catch(Exception e)...{ String msg="不能保存目录"+e.toString(); this.logger.error(msg,e); throw new LibraryException(msg,e); } }