错误记录1
1、org.apache.ibatis.reflection.ReflectionException
nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'chapter' in 'class com.yuan.entity.Chapter'
2、org.apache.ibatis.executor.ExecutorException
org.apache.ibatis.executor.ExecutorException: Statement returned more than one row, where no more than one was expected.
由于查找出了多个对象,一般查找的那个字段是数据有重复。
程序期望返回不超过一行数据,但实际返回了多于一行的数据。
解决方法:
出现这种错误的可能性很多,其中一种便是关联查询问题:比如collection是一对多的查询,而association是一对一的查询。
3、java.lang.IllegalArgumentException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.yuan.mapper.EssayMapper.getEssayMenu
### The error may exist in file [F:\个人项目\在线码字\SpringBootWrite\target\classes\mybatis\mapper\ChapterMapper.xml]
### The error may involve com.yuan.mapper.ChapterMapper.getChapterMenu
解决方法
Mapped Statements collection does not contain value for后面是什么类什么方法之类的:
错误原因有几种:
1、mapper.xml中没有加入namespace
2、mapper.xml中的方法和接口mapper的方法不对应
3、mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),例外:配置了mapper文件的包路径的除外
4、mapper.xml文件名和所写的mapper名称不相同。
我的此次错误是 namespace 错误。
4、java.lang.ClassCastException:
lass java.util.LinkedHashMap cannot be cast to class com.yuan.entity.Book (java.util.LinkedHashMap is in module...
解决方法
导入下面的maven依赖
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<classifier>jdk15</classifier>
</dependency>
然后数据做以下处理
JSONObject jsonObject=JSONObject.fromObject(param.getData()); // 将数据转成json字符串
Book book = (Book) JSONObject.toBean(jsonObject, Book.class); //将json转成需要的对象
5.java.lang.IllegalArgumentException
详细描述
java.lang.IllegalArgumentException: Result Maps collection does not contain value for java.lang.String
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:1031) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.session.Configuration.getResultMap(Configuration.java:740) ~[mybatis-3.5.6.jar:3.5.6]
at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:394) ~[mybatis-3.
解决方法
错误!
<select id="getTitle" resultMap="java.lang.String">
SELECT title
FROM m_cagetory AS category
WHERE category.id = #{id} AND category.user_id = #{user_id}
</select>
正确。
<select id="getTitle" resultType="java.lang.String">
SELECT title
FROM m_cagetory AS category
WHERE category.id = #{id} AND category.user_id = #{user_id}
</select>
但需要注意的是,并不一定是当前SQL操作所使用的mapper.xml文件,那些本次SQL操作不会使用的mapper文件也会导致这个错误。
我的此次错误便是操作UserMapper,但错误在CategoryMapper中。