MyBatis异常 之 Mapped Statements collection does not contain value for xxx

背景

执行mybatis mapper中的一个方法时报错:

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是否存在:

	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>

查看配置:

	<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文件;

解决方案

修改配置

<property name="mapperLocations" value="classpath:mapper/**/*Mapper.xml" />

mapper/**/*Mapper.xml表示包含目录及其子目录下的所有mapper文件

转载于:https://my.oschina.net/mengzhang6/blog/2877075

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值