今天配置springMVC项目时,遇到报错:Invalid bound statement (not found),找了好长时间的bug,终于发现是自己的Mapper.xml文件命名问题,被我命名成Mapping.xml导致出错。
配置Mapper.xml文件时的注意事项
- Mapper.xml的namespace要写所映射接口的全称类名,而且要和Mapper类对应好!
- Mapper.xml中的每个statement的id要和接口方法的方法名相同
- Mapper.xml中定义的每个sql的parameterType要和接口方法的形参类型相同
- Mapper.xml中定义的每个sql的resultType要和接口方法的返回值的类型相同
- Mapper.xml要和对应的mapper接口在同一个包下
- Mapper.xml的命名规范遵守: 接口名+Mapper.xml