1.一对多用户和账户
@Select("select * from user")
@Results(id = "resultMap",value = {
@Result(id = true,property = "userId",column ="id"),
@Result(property = "userName",column ="username"),
@Result(property = "userSex",column ="sex"),
@Result(property = "userAddress",column ="address"),
@Result(property = "accounts",column ="id",many=@Many(select = "com.itheima.dao.IAccountDao.getAccountById",
fetchType = FetchType.LAZY)),
})
List<User> findAll();
2.多对多
是由多个一对多组成,但是会产生中间表,上面的步骤相同,查询需要用到内连接
@Select("SELECT * FROM role WHERE id IN(SELECT rid FROM user_role WHERE uid=#{id}) ")
Role getRoleById(Integer id);