Spring-mybatis整合步骤:
1.导入要使用的jar包(注意版本问题,mybatis配置包,Spring-mybatis包,Spring相关的jar包,数据库连接包等)
2.配置数据库映射文件da.properties
3.配置c3P0数据源,引入外部配置文件
<context:property-placeholder
ignore-unresolvable="true" location="classpath:db.properties" />
<bean id="datasource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${driver}" />
<property name="jdbcUrl" value="${url}" />
<property name="user" value="${name}" />
<property name="password" value="${pwd}" />
<property name="acquireIncrement" value="5"></property>
<property name="initialPoolSize" value="10"></property>
<property name="minPoolSize" value="5"></property>
<property name="maxPoolSize" value="20"></property>
</bean>
4.
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource" />
<property name="configLocation" value="classpath:mybatis-config.xml"></property>
<property name="mapperLocations"
value="classpath*:com/zhiyou/mapper/*.xml" />
</bean>
5.
<bean id="sqlSession"
class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
6.
<bean id="deptMapper"
class="com.zhiyou.mapper.impl.DeptMapperImpl">
<property name="sqlSession" ref="sqlSession"></property>
</bean>