Code Bye

关于树形结构表的Mybatis映射

关于树形结构表的Mybatis映射

表结构如下:

 id parentId  name otherInfo

其中id和parentId关联,形成树形的关系。

POJO如下:

public  class TreePOJO{
	public List<TreePOJO> children;
	//set get方法;
	public void myFunLogic(){
		//logic code;
	}
}

请问,mybatic的映射文件怎么写?

33分

#1

mybatic 自己写sql递归查询吧

#2

请问,mybatis的映射文件怎么写?

#3

<resultMap type=”Knowledge” id=”KnowledgeLeafListMap”>
<id column=”id” property=”id” />
<result column=”knowledgeName” property=”knowledgeName” />
<result column=”isLeaf” property=”isLeaf” />
<result column=”parentKnowledgeId” property=”parentKnowledgeId” />
<result column=”knowledgeContext” property=”knowledgeContext” />
<result column=”knowledgeStatus” property=”knowledgeStatus” />
<result column=”currentVersion” property=”currentVersion” />
<result column=”releaseVersion” property=”releaseVersion” />
<result column=”recycleFlag” property=”recycleFlag” />
<result column=”statFlag” property=”statFlag” />
<result column=”createUser” property=”createUser” />
<result column=”createDate” property=”createDate” />
<result column=”editUser” property=”editUser” />
<result column=”editDate” property=”editDate” />
<result column=”releaseUser” property=”releaseUser” />
<result column=”releaseDate” property=”releaseDate” />
<result column=”remark” property=”remark” />
<association property=”parent” column=”parentKnowledgeId”
select=”selectParent” />
<collection property=”children” column=”id” ofType=”Knowledge”
javaType=”java.util.ArrayList” select=”selectChildren” />
</resultMap>

<select id=”getNotLeafList” resultMap=”KnowledgeLeafListMap”>
select d.* from tb_knowledge d
</select>

<select id=”selectParent” parameterType=”int” resultMap=”KnowledgeLeafListMap”>
select d.* from tb_knowledge d where d.id=#{parentKnowledgeId}
</select>

<select id=”selectChildren” parameterType=”int” resultMap=”KnowledgeLeafListMap”>
select d.id recid, d.* from tb_knowledge d where d.parentKnowledgeId=#{id}
</select>

自己看看呗,比较简单,只是这玩意不适合数据量大的情况


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明关于树形结构表的Mybatis映射