1.先在application.xml中引入注解事务的核心对象,开启事务管理
2.再在需要进行事务的serviceImpl类中添加注解
//@Transactional加在类上面就表示整个类里面的所有的方法都绑定到事务中
@Transactional(propagation=Propagation.REQUIRED)
@Service("billService")
public class BillServiceImpl implements BillService{
@Autowired
BillMapper billMapper;
@Override
public List selectAll(String productName) {
return billMapper.selectAll(productName);
}
@Override
public int addBill(List bills) {
for(int i=0;i
二.在xml中配置连接数据库的方法
1.使用dbcp连接,这种方法是在xml文件中把这个连接写死了
2.引用数据库的配置文件database.properties,这种方法将数据库的配置和调用分开了
引入数据库配置文件
classpath:database.properties
3.配置jndi数据源
先在xml中引入核心对象
java:comp/env/jdbc/news
再在Tomcat的配置文件context.xml中添加数据库配置



