练习MyBatis的时后出现了IllegalArgumentException错误
百度:
1.Mapper 的命名空间没有对接接口 ,namespace的值应该这样<mapper namespace="com.zju.IUserDao">
2.mapper.xml的文件命名里没有包含mapper这个单词
3.配置文件问题
关键是我没有整合,只是测试MyBatis没有使用接口。
我的报错:org.apache.ibatis.exceptions.PersistenceException:
### Error updating database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for user.dynamicUpdate
报错原因:
1.方法名不对应
List<User> list = sqlSession.selectList("user.findByConditionPriority",user);
测试用例中的方法名为“findByConditionPriority”,但是在mapper里写的方法名为“findByConditionPriority ”细心的朋友就会发现多了个空格,对应不成功,找不到相应方法
<select id="findByConditionPriority " parameterType="User" resultMap="userMap">
select <include refid="userColumns"/> from user
<where>
<choose>
<when test="id!=null">
id = #{id}
</when>
<when test="name!=null and name!='' ">
name like'%${name}%'
</when>
<when test="age!=null">
age=#{age}
</when>
<otherwise></otherwise>
</choose>
</where>
</select>
2.后来发现是因为在mapper.xml文件里写的SQL语句里包含了数据库user表里,不存在的字段。删除后。运行成功
解决方法:
删除SQL语句里不存在的的输入映射。
删掉多余的空格。