全注解开发
1.将SpringMVC改为注解
修改spring-mvc.xml
2.将Spring改为注解
将Service改为注解,完成Dao的注入
将事务以注解方式织入到Service
1.修改spring-tx.xml,只负责事务的开启
1 2 34 6 7 85
2.在service中使用注解织入事务
1 @Transactional //声明式的事务管理2 public void add(Student student) {3 studentDao.insert(student); 4 }
3.将Mybatis 改为注解(删除mapper文件)(一般Mybatis不使用注解)
1 public interface StudentDao {2 //一般 情况下,为了 性能考虑, mybatis是不进行 注解的 3 @Insert(value="insert into student (sname) values (#{sname})")4 void insert(Student student);5 }