事务配置部分的XML:如下
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:annotation-driven
transaction-manager="transactionManager" proxy-target-class="true"/>
然后 service层 使用@Transactional(rollbackFor= { Exception.class })
代码如下:
@Transactional(rollbackFor= { Exception.class })
public String update(Employee employee) {
if (employee.getId() != null && employee.getId() > 0) {
employeeMapper.update(employee);
int a = 1/0;
} else {
employeeMapper.insert(employee);
}
return "200";
}
查一下数据库引擎是否是innodb