執行mybatis mapper中的一個方法時報錯:java
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.xxx.mapper.SysDictionaryMapper.findByTypeCode org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:672) org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:507) org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:500) org.apache.ibatis.binding.MapperMethod.setupCommandType(MapperMethod.java:240)
查看SysDictionaryMapper.findByTypeCode是否存在:spring
SysDictionaryMapper.java List<SysDictionaryDO> findByTypeCode(@Param("typeCode") String typeCode); SysDictionaryMapper.xml <select id="findByTypeCode" resultMap="BaseResultMap"> SELECT <include refid="baseColumn"/> FROM <include refid="tableName"/> WHERE type_code = #{typeCode} and del_status = 0 ORDER BY sort </select>
查看配置:sql
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="configLocation" value="classpath:mybatis-config.xml" /> <property name="mapperLocations" value="classpath:mapper/*Mapper.xml" /> <property name="plugins"> <array> <bean class="com.xxx.interceptor.MapInterceptor"/> <bean class="com.xxx.interceptor.ParamterInterceptor"/> </array> </property> </bean>
經過分析發現,SysDictionaryMapper.xml並非在mapper目錄下,而是在其子目錄下,因此致使找不到該mapper文件;apache
修改配置session
<property name="mapperLocations" value="classpath:mapper/**/*Mapper.xml" />
mapper/**/*Mapper.xml表示包含目錄及其子目錄下的全部mapper文件mybatis