一对一
@Results(id = "userMap",
value = {@Result(id = true,property = "userId",column = "id"),
@Result(property = "userName",column = "name"),
@Result(property = "userAge",column = "age"),
@Result(property = "rId",column = "r_id"),
@Result(property = "UDid",column = "u_Did"),
@Result(column = "u_Did",
property = "department",
one = @One(select = "com.zhiyou100.dao.DepartmentDao.queryById")
)}
)
// @One 相当于 xml 文件中的 association 标签
// column 代表数据库中的字段
// property 代表 pojo 类中的属性 和上面的column 形成一一对应的关系
// results 注解对应的 id值 可以使用 @ResultMap注解 引用
一对多:
@Results(
id = "departmentMap2",
value = {
@Result( id = true,property = "did",column = "d_id"),
@Result(property = "departmentName",column = "d_name"),
@Result(property = "departmentDesc",column = "d_desc"),
@Result(property = "departmentUpdate",column = "d_updateTime"),
@Result(column = "d_id",
property = "users",
javaType = List.class,
many = @Many(
select = "com.zhiyou100.dao.UserDao.queryByDid"
/* ,
fetchType = FetchType.LAZY*/
)
)
}
)
// fetchType 是否开启延迟加载 FetchType.LAZY 开启 FetchType.EAGER 不开启