主动抛出异常
有时候我们需要做一些主动抛出异常的操作,而这样做主要是让spring来捕获异常,让事务可以回滚,在spring使用事物时可以使用trycatch,但是你要在catch方法里抛出RuntimeException,因为spring捕获的就是RuntimeException这个异常。代码如下
try{logger.debug(sql);jdbcDao.getJdbcTemplate().batchUpdate(sql,pps);}catch(Exception ex){save = false;// 把错误写进日志logger.error("保存项目审查条件出错!!", ex);throw new RuntimeException(ex);}