...">
美文网首页
mybatis 一对多 级联查询

mybatis 一对多 级联查询

作者: cjlynn | 来源:发表于2019-06-05 20:21 被阅读0次

1、SQL MAPPER

<resultMap id="AllResultMap" type="Submsg">

    <id property="id" column="id"  />

    <result property="name" column="name" />

    <collection property="roles"  ofType="Role" >

        <id column="role_id" property="id"  />

        <result  column="role_name"  property="name"/>

    </collection>

</resultMap>

<select id="queryList" parameterType="Submsg" resultMap="AllResultMap">

    select t.*,

    r.id as role_id,r.name as role_name

    from submsg as t

    left outer join submsg_sp p on t.id = p.submsg_id

    left outer join sys_role r on p.receive_id = r.id and p.receive_type='ROLE'

</select>

2、java对象

@Component

public interface SubmsgDao {

    List<Submsg> queryList(@Param("po") Submsg ps);

}

@Data

@Table(name ="submsg")

public class Submsg {

    @Id

    private String id;

    private String name;

    @Transient

    private List<Role> roles;

}

相关文章

网友评论

      本文标题:mybatis 一对多 级联查询

      本文链接:https://www.haomeiwen.com/subject/ixzsxctx.html