详细一点说:
就是能不能在association,collection中的select属性中引用另外一个xml中定义的select语句?例如
teacher表的select定义
<select id="getTeacherById" resultMap="teacherResultMap" resultType="String">
SELECT *
FROM TEACHER_TBL
WHERE TEACHER_ID = #{teacherID}
</select>
class表的resultMap定义
<resultMap type="ClassEntity" id="classResultMap">
<id property="classId" column="CLASS_ID" />
<result property="className" column="CLASS_NAME" />
<result property="classYear" column="CLASS_YEAR" />
<association property="teacherEntity" column="TEACHER_ID"
select="getTeacherById" />
</resultMap>
错误的意思好像是当前命名空间找不到select
## Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.citicbank.km.mis.dao.ClassMapper.getTeacherById
### The error may involve com.citicbank.km.mis.dao.ClassMapper.getClassAllbyClassId-Inline
### The error occurred while setting parameters
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.citicbank.km.mis.dao.ClassMapper.getTeacherById, mergedContextConfiguration = [MergedContextConfiguration@1abe675c testClass = MybatisTest, locations = '{classpath:spring-config.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [false].
[org.springframework.test.context.support.DirtiesContextTestExecutionListener]After test class: context [DefaultTestContext@5abc30ad testClass = MybatisTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [MergedContextConfiguration@1abe675c testClass = MybatisTest, locations = '{classpath:spring-config.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], dirtiesContext [false].
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.386 sec <<< FAILURE!
[org.springframework.context.support.GenericApplicationContext]Closing org.springframework.context.support.GenericApplicationContext@c25b3d5: startup date [Fri Aug 29 23:42:48 CST 2014]; root of context hierarchy
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Returning cached instance of singleton bean 'lifecycleProcessor'
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2c9b0a66: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.support.PropertySourcesPlaceholderConfigurer#0,dataSource,transactionManager,sqlSessionFactory,org.mybatis.spring.mapper.MapperScannerConfigurer#0,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,classMapper,studentMapper,teacherMapper]; root of factory hierarchy
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Retrieved dependent beans for bean 'classMapper': [com.citicbank.km.mis.test.MybatisTest]
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Retrieved dependent beans for bean 'dataSource': [sqlSessionFactory]
[org.springframework.beans.factory.support.DefaultListableBeanFactory]Retrieved dependent beans for bean 'sqlSessionFactory': [org.mybatis.spring.mapper.MapperScannerConfigurer#0]
[org.springframework.beans.factory.support.DisposableBeanAdapter]Invoking destroy method 'close' on bean with name 'dataSource'
[com.alibaba.druid.pool.DruidDataSource]{dataSource-1} closed
那你是用namespace.id试试
也就是假设<select id="getTeacherById">所在的xml文件的命名空间为A,那么就写作A.getTeacherById
行不通...
解决了吗 我也超好奇这个问题!!
可以使用select语句,但是要为该语句的全包名