zoukankan      html  css  js  c++  java
  • Spring6——Spring整合Mybatis

    Spring整合Mybatis
    思路:将Mybatis的SqlSessionFactory交给Spring。
     
    SM整合步骤:
    1.jar
    2.类-表
     
    3.mybatis配置文件conf.xml
     
    4.通过mapper.xml将类、表建立映射关系
     
    5.spring管理SqlSessionFactory
    配置spring配置文件:applicationContext.xml
     
    6.使用Spring-MyBatis整合产物开发程序
    目标:通过Spring产生Mybatis最终操作需要的动态mapper对象。
    (1)DAO层实现类,继承SqlSessionDaoSupport类,该类提供了一个属性SqlSession
    (2)省略第一种方式中的实现类
    直接使用MyBatis提供的实现类org.mybatis.spring.mapper.MapperFactoryBean。
    (3)批量处理:批量配置实现类
    注意:批量产生mapper对在ioc中的id值默认为接口名,接口名=id,接口名首字母小写
     
    注解形式的依赖注入
    //实现bean
    @Service("studentService")
    public class StudentServiceImpl implements IStudentService {
        //实现ioc中的注入,自动装配,默认byType
        @Autowired
        //根据name来注入
        @Qualifier("studao")
        IStudentDao studentDao;
    
        public IStudentDao getStudentDao() {
            return studentDao;
        }
    
        public void setStudentDao(IStudentDao studentDao) {
            this.studentDao = studentDao;
        }
    }
    

      

  • 相关阅读:
    快速幂 快速乘法
    扩展欧几里得学习笔记
    求逆序数数目(树状数组+离散化)
    隐式图的遍历
    随机数生成
    推倒重来
    动态规划初步
    子集生成
    东大oj1155 等凹函数
    P1278 单词游戏
  • 原文地址:https://www.cnblogs.com/ghlz/p/13182073.html
Copyright © 2011-2022 走看看