使用Mybatis的常见错误

如果Mapper接口不在`@MapperScan`指定的包下,或根本没有配置`@MapperScan`,总之,Mybatis找不到Mapper接口时,会出现错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
 No qualifying bean of type 'cn.tedu.csmall.product.mapper.AlbumMapper' available: 
expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}

如果存在以下问题:

- 在XML文件中``标签的`namespace`值有误
- 在XML文件中``这类标签的`id`值有误
- 在配置文件中`mybatis.mapper-locations`属性的值有误总之,当Mybatis找不到抽象方法映射的SQL语句时,会出现错误:

org.apache.ibatis.binding.BindingException: 
Invalid bound statement (not found): 
cn.tedu.csmall.product.mapper.AlbumMapper.insert

如果配置SQL语句时,在`#{}`格式的占位符中,名称写错时,会出现错误:

Caused by: 
org.apache.ibatis.reflection.ReflectionException: 
There is no getter for property named 'nama' in 
'class cn.tedu.csmall.product.pojo.entity.Album'

如果配置``标签时,使用`resultType`,但值却是某个``的id,或是错误的全限定名,会出现错误:

Caused by: 
java.lang.ClassNotFoundException: Cannot find class: StandardResultMap

 

如果配置`