出现错误的关键代码如下:
// 接口
@Results(id = "roleResultMap", value = {
@Result(property = "id", column = "id", id = true),
@Result(property = "roleName", column = "role_name"),
@Result(property = "enable", column = "enable"),
@Result(property = "createBy", column = "create_by"),
@Result(property = "createTime", column = "create_time")
})
@ResultMap("roleResultMap")
@Select("select id, role_name, enable, create_by, create_time " +
"from sys_role where id = #{id}" )
SysRolePo selectById2(Long id);
测试改接口,出现如下错误。
org.apache.ibatis.builder.IncompleteElementException: Could not find result map com.echo.springmybatis.mapper.SysRoleMapper.roleResultMap
at org.apache.ibatis.builder.MapperBuilderAssistant.getStatementResultMaps(MapperBuilderAssistant.java:346)
at org.apache.ibatis.builder.MapperBuilderAssistant.addMappedStatement(MapperBuilderAssistant.java:290)
at org.apache.ibatis.builder.annotation.MapperAnnotationBuilder.parseStatement(MapperAnnotationBuilder.java:351)
at org.apache.ibatis.builder.annotation.MethodResolver.resolve(MethodResolver.java:33)
……
错误提示的意思很明显就是找不到roleResultMap,但是明显@ResultMap("roleResultMap")最上面就是对应的值。
解决方案
@Results(id = "roleResultMap", value = {
@Result(property = "id", column = "id", id = true),
@Result(property = "roleName", column = "role_name"),
@Result(property = "enable", column = "enable"),
@Result(property = "createBy", column = "create_by"),
@Result(property = "createTime", column = "create_time")
})
@Select("select id, role_name, enable, create_by, create_time " +
"from sys_role where id = #{id}")
SysRolePo selectById2(Long id);
@ResultMap("roleResultMap")
@Select("select * from sys_role")
List<SysRolePo> selectAll();
这两个注解,接口上面只能有一个存在,ResultMap又依赖于Results,用ResultMap的时候只是公用其它的Results