mybatis和spring一起使用要加依赖
org.mybatis
mybatis-spring
2.0.2
org.springframework
spring-jdbc
5.1.9RELEASE
配置文件中配置SqlSessionFactoryBean
1.<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation value="classpath:可以配原先的配置文件但是会多出一个配置文件"/>
2.<bean id="dataSourece class="com.mysql.jdbc2.optional.MysqlDataSource">
<property name="url" value="${url}/>
<property name="user" value="${user}/>
<property name="password" value="${password}/>
</bean>
<bean class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property nane="typeAliasesPakage" value="模型包路径" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value"mapper包的路径" />
</bean>