Mybatis many=@Many的传值问题,子查询调用主查询的结果参数

您所在的位置:网站首页 mybatis参数传递调用方法 Mybatis many=@Many的传值问题,子查询调用主查询的结果参数

Mybatis many=@Many的传值问题,子查询调用主查询的结果参数

2024-07-03 05:27| 来源: 网络整理| 查看: 265

@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 selectByUserNameRoleId(@Param("userId") String userId);

三个表 user role user_role为关联表 ①主查询,查询得到结果。 将结果里面的id字段赋给③,③里面的id为子查询的条件,③的id与①里面的数据库字段相对应。 selectByUserNameRoleId通过③的coulmn为查询条件。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3