MyBatis框架

9.3.5 Spring 整合MyBatis 配置

<!– Spring 整合 Mybatis –>

         <!–1. SqlSession  –>

         <bean class=“org.mybatis.spring.SqlSessionFactoryBean”>

                   <!– 指定数据源 –>

                   <property name=dataSource” ref=“dataSource”></property>

                   <!– MyBatis的配置文件 –>

                   <property name=configLocation”

                 value=“classpath:mybatis-config.xml”></property>

                   <!– MyBatis的SQL映射文件 –>

                   <property name=mapperLocations”

                 value=“classpath:mybatis/mapper/*.xml”></property>

                   <property name=typeAliasesPackage”

                 value=“com.atguigu.ssm.beans”></property>

         </bean>

         <!– Mapper接口

                   MapperScannerConfigurer 为指定包下的Mapper接口批量生成代理实现类.bean的默认id是接口名首字母小写.

          –>

         <bean class=“org.mybatis.spring.mapper.MapperScannerConfigurer”>

                   <property name=basePackage” value=“com.atguigu.ssm.mapper”></property>

         </bean>

         <!– <mybatis-spring:scan base-package=”com.atguigu.ssm.mapper”/> –>

 

 

9.4 整合测试

 

 


上一篇:
下一篇: