`
esffor
  • 浏览: 1352176 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Spring中关于保存数据时重名的处理异常

阅读更多

其中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);
        }

        
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics