mybits多对多、一对一

一、多对一 | 一对一

<resultMap type="com.zktx.platform.entity.tb.Module" id="BaseResultMap">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="class_name" jdbcType="VARCHAR" property="class_name"/>
        <result column="description" jdbcType="VARCHAR" property="description"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="priority" jdbcType="INTEGER" property="priority"/>
        <result column="sn" jdbcType="VARCHAR" property="sn"/>
        <result column="url" jdbcType="VARCHAR" property="url"/>
        <result column="parent_id" jdbcType="INTEGER" property="parent_id"/>
        <association column="parent_id" property="parent_Module" select="selectById"></association>
    </resultMap>
    
    <select id="queryList" resultMap="BaseResultMap">
        select * from tb_module m1 left join tb_module m2 on m1.parent_id =m2.id 
    </select>
    <select id="selectById"  parameterType="java.lang.Integer" resultType="com.zktx.platform.entity.tb.Module">
        select * from tb_module where id=#{parent_id}
    </select>

dao层:

List<Module> queryList();

二、一对多|多对多

xml配置文件

com.dataManage.mapper.UmTGroupMapper.xml中

<resultMap id="umTGroup" type="com.dataManage.entry.UmTGroup">
      <id column="id" property="id"/>
      <result column="code" property="code"/>
      <result column="name" property="name"/>
      <result column="pid" property="pid"/>
      <result column="description" property="description"/>
      <result column="areaid" property="areaid"/>
      <collection property="umTRoles" column="id" fetchType="lazy" select="com.dataManage.mapper.UmTRoleMapper.findUmTRolesByGId"></collection>
  </resultMap>
  <select id="selectAll" resultMap="umTGroup">
        SELECT * FROM um_t_group
    </select>
com.dataManage.mapper.UmTRoleMapper.xml中:
<select id="findUmTRolesByGId" resultMap="umTRoleMapper">
        SELECT * FROM um_t_role r LEFT JOIN um_t_g_r gr ON r.id=gr.rid WHERE gr.gid=#{groupid}
    </select>

Dao层

UmTRoleMapper.java中:

public List<UmTRole> findUmTRolesByGId(@Param("groupid") Integer groupid);

UmTGroupMapper.java中

 public List<UmTGroup> selectAll();




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值