1.指定异常 捕获比当前异常小的
@Transactional(rollbackFor={RuntimeException.class, Exception.class})
2.方法抛出异常 事务捕获异常
@Transactional(rollbackFor={Exception.class}) public void renewCompany() throws Exception { try{ //1.删除机构表中的所有数据 prpdcompanywxSynDao.deleteAll(); //2.调用网销接口获取最新的机构表数据 String url = "http://localhost:7001/ebusiness/intefPropertyInsuranceServlet"+"?actionType=getPrpdCompanyInfo"; HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); //准备接受返回的字符串 String response = ""; client.executeMethod(method); if (method.getStatusCode() == HttpStatus.SC_OK) { //接收返回字符串 response = method.getResponseBodyAsString(); logger.warn("response:"+response); JSONObject jsonObject = JSON.parseObject(response); JSONArray jsonArray = jsonObject.getJSONArray("data"); List<PrpdcompanywxSyn> dataArr = JSONArray.parseArray(jsonArray.toString(), PrpdcompanywxSyn.class); //3.插入到机构表中 prpdcompanywxSynDao.insertAll(dataArr); /* for(PrpdcompanywxSyn data : dataArr){ prpdcompanywxSynDao.insertSelective(data); }*/ } else { logger.warn("请求网销接口getPrpdCompanyInfo失败" + method.getStatusLine()); } }catch (Exception e){ logger.warn("请求网销接口失败"); e.printStackTrace(); throw new Exception(e.getMessage()); } } }
https://blog.csdn.net/weixin_33656548/article/details/80447460