mybatis 查詢樹形結構


1.表結構

CREATE TABLE `flow_app_info` (
  `id` int(11) NOT NULL,
  `parentid` int(11) DEFAULT NULL,
  `name` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

2.實體類

@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppInfo {
    private int id;
    private int parentid;
    private String name;
    private List<AppInfo> childList;
}

3.mapp.xml

    <resultMap id="appsTree" type="com.lg.business.common.ws.AppInfo">
        <id column="id" property="id" javaType="int"/>
        <result column="parentid" property="parentid" javaType="int"/>
        <result column="name" property="name" javaType="String"/>
        <collection column="id" property="childList" select="getAppsByPid"/>
    </resultMap>

    <select id="getAllWsAppList" resultMap="appsTree">
        select id,parentid,name from flow_app_info where parentid=0
    </select>

    <select id="getAppsByPid" resultMap="appsTree">
        select id,parentid,name from flow_app_info where parentid=#{id}
    </select>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM