首先是applicationContext.xml文件
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="modify*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="search*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="transactionPointcut"
expression="execution(* com.adon.service..*.*(..))" />
<aop:advisor pointcut-ref="transactionPointcut"
advice-ref="transactionAdvice" />
</aop:config>
接下来是service实现类中的代码
public JSONObject confirmPassport(String id) throws Exception{
PassPortManage pm = new PassPortManage();
JSONObject json = new JSONObject();
try {
pm.setId(new BigDecimal(id));
//已确认
pm.setConfirmed(new BigDecimal("1"));
Integer i = passPortManageMapper.updateByPrimaryKeySelective(pm);
int q = 5/0;
if(1==i){
json.put("success", true);
json.put("msg", "签收成功!");
}else{
json.put("success", false);
json.put("msg", "签收失败(sql异常)");
}
} catch (Exception e) {
e.printStackTrace();
json.put("success", false);
json.put("msg", "签收失败(其他异常)");
throw new RuntimeException();
}
return json;
}
在int q = 5/0;执行后程序会报错,但记录依旧更改了
求大侠们指教