报错信息
Invalid bound statement (not found): com.qianfeng.automation.user.mapper.AutomationUserDao.insertSective
类似出现上面这个错误时,按以下步骤检查一定就会解决问题:
1,以maven项目为例:xml文件默认需要放在recource目录下或recource目录下的文件夹下。maven默认不会加载java目录下的xml‘文件,如果一定要放在java目录下,需要在pom.xml下修改maven的默认配置。
<!-- 此处是为了方面在java目录中读取xml配置文件 如果不加 默认的只能在resources目录中读取-->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>false</filtering>
</resource>
2:检查xml文件所在package名称是否和Mapper interface所在的包名对应,如果不希望对应需要在mybatis的配置文件中添加;
//此为在yml或者yaml配置文件中写法,其中mapper是recource目录下存放xml文件的文件夹
mapper-locations: classpath:mapper/*.xml
//此为properties配置文件中的写法
mybatis.mapperLocations=classpath:mapper/*.xml
3:检查xml的namespace是否和mapper接口全路径名称(包名+类名)对应;
<mapper namespace="com.automation.user.mapper.UserDao">
...
</mapper>
4:检查方法名称和xml文件中标签id是否对应,parameterType参数类型是否正确,返回值类型resultType或者resultMap是否正确;
5:检查数据库表字段的容量大小是否够用,字段多少和实体类字段多少是否一致
6:还不行,重新打包项目或者删除target文件重新运行