zoukankan      html  css  js  c++  java
  • 20.SSM整合-全注解开发

    全注解开发

      1.将SpringMVC改为注解

        修改spring-mvc.xml

      2.将Spring改为注解

          将Service改为注解,完成Dao的注入

          将事务以注解方式织入到Service

            1.修改spring-tx.xml,只负责事务的开启     

    1 <!-- 配置事务管理器 -->
    2     <!-- 开启Spring中的事务管理(声明式的事务管理) xml-->
    3     <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    4         <property name="dataSource" ref="dataSource"></property>
    5     </bean>
    6     
    7     <!-- 事务注解 驱动,使用注解进行事务管理时 需要注册 -->
    8     <tx:annotation-driven transaction-manager="transactionManager"/>

            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 }
  • 相关阅读:
    线程进程之间的关系
    socket网络编程
    Docker在github上的站点
    大型网站架构体系的演变
    centos7 安装SSH
    如何在CentOS 7中禁用IPv6
    在 Docker 上运行一个 RESTful 风格的微服务
    docker 操作命令详解
    玩转Docker镜像
    搭建自己的 Docker 私有仓库服务
  • 原文地址:https://www.cnblogs.com/xuzekun/p/7418044.html
Copyright © 2011-2022 走看看