mybatis-plus报错解决Invalidboundstatement(notfound)错误mybatis-plus报错解决Invalid bound statement (not found)错误
异常信息
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): XXMapper.findTagList
也就是在mybatis中dao层xxxMapper接⼝与l⽂件在做映射绑定的时候出现问题,也就是xxxMapper接⼝⽆法匹配到操作sql语句的⽅法id~
源码解析
⾸先断点打在调⽤mapper⽅法的地⽅
tagMapper.findTagList();
继续⾛,进⼊MapperMethod.java类:
public SqlCommand(Configuration configuration, Class<?> mapperInterface, Method method) {
//methodName就是调⽤的⽅法名
final String methodName = Name();
//declaringClass就是 Mapper接⼝类
final Class<?> declaringClass = DeclaringClass();
//问题出在这⾥返回为空:原因是没有到该接⼝类
MappedStatement ms = resolveMappedStatement(mapperInterface, methodName, declaringClass,
configuration);
if (ms == null) {
if (Annotation(Flush.class) != null) {
name = null;
type = SqlCommandType.FLUSH;
} else {
throw new BindingException("Invalid bound statement (not found): "
+ Name() + "." + methodName);
}
} else {
name = ms.getId();
type = ms.getSqlCommandType();
if (type == SqlCommandType.UNKNOWN) {
throw new BindingException("Unknown execution method for: " + name);
}
}
}
private MappedStatement resolveMappedStatement(Class<?> mapperInterface, String methodName,
Class<?> declaringClass, Configuration configuration) {
//Method
String statementId = Name() + "." + methodName;
//configuration有⼀个⼤集合,缓存了所有的Mapper及所有的⽅法
if (configuration.hasStatement(statementId)) {
MappedStatement(statementId);
} else if (mapperInterface.equals(declaringClass)) {
return null;
}
for (Class<?> superInterface : Interfaces()) {
if (declaringClass.isAssignableFrom(superInterface)) {
MappedStatement ms = resolveMappedStatement(superInterface, methodName,
declaringClass, configuration);
if (ms != null) {
return ms;
}
}
}
return null;
}
}
问题就在这⾥,mappedStatements没有⼯程的mapper,原因就是没有扫描到,即定位到扫描时配置问题!
解决⽅案
1. 检查xml映射⽂件中<mapper>标签绑定包名地址是否正确(即namespace的值)
2. 检查xxxMapper接⼝中的⽅法,对应xml映射⽂件中是否有
3. 检查<select>标签中的resultType是否与xxxMapper接⼝中的⽅法返回值类型⼀致,若⼀个是对象⼀个是集合,那也会报错~
4. 检查yml配置⽂件中的mybatis配置invalids
配置项 mybatis -> mybatis-plus
mybatis-plus:
mapper-locations: classpath*:com/xxx/*l
typeAliasesPackage: ity
5. xml资源配置
maven:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.tld</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
gradle:
processResources {
from('src/main/java') {
include '**/xml/*.xml'
}
}
问题解决!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。