本篇记录操作Mybatis所遇到的错误
Caused by: java.lang.IllegalArgumentException: Result Maps collection does not contain value for XXX
该异常,从字面意思很难找到错误,所以记录一下。在以注解形式操作Mybatis的时候,需要将定义且带id的@Result
放在坐前面。
这是错误的:
//上面还有
@Results(id = "roleResultMap", value = {
@Result(property = "id",column = "id", id = true),
@Result(property = "roleName", column = "role_name"),
@Result(property = "enabled", column = "enabled"),
@Result(property = "createBy", column = "create_by"),
@Result(property = "createTime", column = "create_time")
})
@ResultMap("roleResultMap")
@Select({"select * from sys_role"})
List<SysRole> selectAll();
这是正确的:
public interface RoleMapper {
//Results带id的需要放在Mapper最前面
@Results(id = "roleResultMap", value = {
@Result(property = "id",column = "id", id = true),
@Result(property = "roleName", column = "role_name"),
@Result(property = "enabled", column = "enabled"),
@Result(property = "createBy", column = "create_by"),
@Result(property = "createTime", column = "create_time")
})
}