mybatis-spring:MapperScannerConfigurer、MapperScannerConfigurer

前言

Mybatis逆向工程可以生成pojo类、Mybatis配置文件、dao。另外需要一个Mybatis的配置文件将这些生成的代码进行整合。

配置

    
    
        
        
        
    

    
        
        
    


SqlSessionFactoryBean

在spring上下文中实例化一个共享的Mybatis sql session工厂,然后将这个SQLSessionFactory通过依赖注入注入给基于Mybatis的DAOs。

MapperScannerConfigurer

继承自BeanDefinitionRegistryPostProcessor,他会从一个Base package开始,遍历所有子目录下的接口,并将这些接口注册为MapperFactoryBean, (只有包含至少一个接口方法的接口才会被注册)。

public interface UserInfoMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(UserInfo record);

    int insertSelective(UserInfo record);

    UserInfo selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(UserInfo record);

    int updateByPrimaryKey(UserInfo record);
}




你可能感兴趣的:(java)