@Select({“select * from user where username = #{userName}”}) ①
@Results({
@Result(
property = “id”, column = “id” ②
),
@Result(
property = “roleList”,column=“id”, ③
many = @Many(select = “com.x.dt.mapper.UserMapper.selectByUserNameRoleId”)
)})
List selectByName(String userName);
@Select({"select id from role where id in(select role_id from user_role where user_id=#{userId})"})
List<Role> selectByUserNameRoleId(@Param("userId") String userId);
三个表
user role
user_role为关联表
①主查询,查询得到结果。 将结果里面的id字段赋给③,③里面的id为子查询的条件,③的id与①里面的数据库字段相对应。
selectByUserNameRoleId通过③的coulmn为查询条件。