mybatis中出现Mapped Statements collection does not contain value for...错误原因分析

<!-- by fyw find -->
	<select id="findbySalary" parameterType="double" resultMap="studentMap2">
	select students_id,students_name,students_sal
	from students2
	where students_sal= #{FYW_double}
	
	</select>
在测试过程中,系统总是出现如下异常:
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for studentNamespace.findbySalary
	at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:672)
	at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:507)
	at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:500)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:100)
	... 4 more

经过检查,

(1)在mybatis配置文件中,mapper映射文件配置没有错误。

(2)XML文件中的namespace也没有错误。

(3)mapper.xml中的方法和接口mapper的方法对应;

(4)xml文件和接口文件在同一个目录下。

(5)对应返回的封装类必须写select时要一一对应

select students_id,students_name,students_sal
	from students2
	where students_sal= #{FYW_double}

颠倒顺序会导致不能查询到后自动封装。

查阅资料之后,发现还有一条需要遵循的规律,即对应的xml文件和接口文件的文件名称必须相同。


猜你喜欢

转载自blog.csdn.net/qq_28863045/article/details/80731873