1. 程式人生 > >ssm配置檔案引用細節

ssm配置檔案引用細節

ssm框架整合的時候有三層,service,dao,control。

Spring配置檔案中這三層對應的物件採用設值注入(..)之間引用傳遞,其中dao層採用不同的類則使用不同的屬性,講的好亂~~

上例項

<!-- 配置dao -->
<bean id="SchoolDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
	<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
	<property name="mapperInterface" value="dao.ISchoolDao"/>
</bean>
<bean id="TeacherDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
	<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
	<property name="mapperInterface" value="dao.ITeacherDao"/>
</bean>
<!--  配置service-->
<bean id="service" class="service.PublicServiceImpl">
	<property name="schoolDao" ref="SchoolDao"/>
	<property name="teacherDao" ref="TeacherDao"/>
</bean>

其中配置dao:class="org.mybatis.spring.mapper.MapperFactoryBean"若使用此class則屬性配置如下

<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
<property name="mapperInterface" value="dao.ISchoolDao"/>此處value為介面全路徑

<!-- 生成dao的代理物件 -->
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        	<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        	<property name="basePackage" value="com.dao"/>
        </bean>
        <bean id="studentService" class="com.service.StudentServiceImpl">
         	<property name="dao" ref="IStudentDao"></property>
        </bean>

其中配置:class="org.mybatis.spring.mapper.MapperScannerConfigurer"若使用此class則屬性配置如下

<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
 <property name="basePackage" value="com.dao"/>此處為包路徑