XML

<resultMap id="sub-menu-map" class="menu">  
        <result property="id" column="subid" />  
        <result property="name" column="subname" />   
</resultMap>   
<resultMap id="menu-map" class="menu" groupBy="id">  
        <result property="id" column="id" />  
        <result property="name" column="name" />   
        <result property="subMenus" resultMap="sys.sub-menu-map" />   
</resultMap>  

SQL

select     t.*  from menu t left join menu s   
    on t.id = s.parentid    
where t.layer=1 order by t.position, s.position