下面是几条人能看懂的报错信息
1. jakarta.servlet.ServletException: Servlet[Myspringmvc]的Servlet.init()引发异常
2. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-dao.xml]: Failed to parse config resource: class path resource [mybatis-config.xml]
3. java.io.IOException: Failed to parse config resource: class path resource [mybatis-config.xml]
4. org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/dlz/dao/BookMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...}
5. org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/dlz/dao/BookMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...}
6. org.apache.ibatis.builder.BuilderException: Parsing error was found in mapping #{}. Check syntax #{property|(expression), var1=value1, var2=value2, ...}
7. java.lang.StringIndexOutOfBoundsException: String index out of range: 0
记录一下改报错的历程
前三条基本没啥用,重点从第4条开始,大致意思就是BookMapper.xml文件有问题,那我就去找,一看没啥大问题,难道实体类写错了?那我就去实体类找,果然发现错误。
private int bookID;
private String bookname;
private int bookConunts;
private int detail;
bookConunts跟数据库中的bookCounts不一致,detail应该是String类型的。
然后我改完实体类,还是报以上错误,说明我刚才把实体类改好,但是没有起到任何作用(似乎Mybatis对这类错误容忍度很高),报错压根就不是这个实体类错误引起的,BookMapper.xml文件的错误依旧没有解决。
然后继续找,我发现报错信息中有一个提示
Parsing error was found in mapping #{}
而我的xml文件中
<delete id="deleteBook" parameterType="int">
delete
from ssmbuild.books
where bookID = #{}
</delete>
对应的方法
int deleteBook(@Param("bookID") int id);
好家伙,没写上bookID,Mybatis找不到对应关系。
加上之后
<delete id="deleteBook" parameterType="int">
delete
from ssmbuild.books
where bookID = #{bookID}
</delete>
运行,完美!
续记:
后面我尝试了不修改实体类的错误,果然报错了
Request processing failed: org.springframework.dao.DataIntegrityViolationException:
Error attempting to get column 'detail' from result set. Cause: java.sql.SQLDataException: Cannot determine value type from string '从入门到放弃'
大意就是detail出问题了,改完detail之后,完美运行!(没改bookConunts)
同时也说明这个bookConunts跟数据库中的bookCounts不一致,对Mybatis不影响。