一,java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.study.mapper.TypesMapper.selectTypeById
IllegalArgumentException是一个数据异常的错误,一般是配置文件或者mapper.xml文件中映射出错
错误原因有几种:
1、mapper.xml中没有加入namespace
2、mapper.xml中的方法和接口mapper的方法不对应
3、mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),例外:配置了mapper文件的包路径的除外
4、mapper.xml文件名和所写的mapper名称不相同。
我的是第三种mapper.xml没有加入到mybatis-config.xml中(即总的配置文件),经改正完美运行
二,maven项目编译错误,在target/classes找不到相应的mapper.xml文件
这是因为src/main/java中的xml没有编译进target目录中,只需要在pom.xml中的build标签下加入:
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
三,Mysql错误:check the manual that corresponds to your MySQL server version for the right syntax
注意,一般这种错误是sql语句的错误,请检查sql语句(我的错误是match关键字冲突)
特别注意要查看sql语句中是否mysql的关键字,也就是数据库表中的某个字段名称和mysql关键字冲突
四, org.springframework.dao.DataIntegrityViolationException(这个异常是当插入、删除和修改数据的时候,违背的数据完整性约束抛出的异常):
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: java.sql.SQLException: Data truncated for column 'field_mark' at row 1
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: UPDATE user_field_grade SET field_mark=? WHERE user_field_grade.user=? AND matchs=? AND groups=?
### Cause: java.sql.SQLException: Data truncated for column 'field_mark' at row 1
; SQL []; Data truncated for column 'field_mark' at row 1; nested exception is java.sql.SQLException: Data truncated for column 'field_mark' at row 1
原因:字段截断错误,经排查发现是数据库里面本来的一个varchar类型被改为double所以出错,更正为varchar解决