结果映射配置: 原来xml中的<resultMap>对应 @results
@Select("select * from t_account where id = #{id}")
@Results(id = "accountMap", value = {
@Result(id = true, column = "id", property = "id"),
@Result(column = "user_id", property = "user",
one = @One(
select = "cn.ann.mapper.UserMapper.getUserById", fetchType = FetchType.EAGER
))
})
Account getAccountById(Integer id);
@Result(id = true, column = "id", property = "id")
@Select("select * from t_user where id = #{id}")
@Results(id = "userMap", value = {
@Result(id = true, property = "id", column = "id"),
@Result(property = "accounts", column = "id",
many = @Many(select = "cn.ann.mapper.AccountMapper.getAccountsByUserId",
fetchType = FetchType.LAZY))
})
User getUserById(Integer id);
@ResultMap("accountMap")
原文:https://www.cnblogs.com/ann-zhgy/p/11763821.html