对于这个问题有两种情况:
1.catch只打印异常,不抛出异常
try {
数据库做添加订单表;
int a=5/0;
数据库减少库存;
}catch (Exception e){
e.printStackTrace();
}
此方法会影响事务,此时数据库中订单数据会插入成功!因为Spring的事物的标准是RuntimeException
2.catch打印异常,并抛出异常
try {
数据库做添加订单表;
int a=5/0;
数据库减少库存;
}catch (Exception e){
e.printStackTrace();
throw new RuntimeException();
}
此方法不会影响事务,因为抛出了RuntimeException