mybatis ,使用instance


獲取樹形結構目錄:

pojo參數類

public class TargetPackageDir implements Serializable{
   private Integer dirId;
   private String dirName;
   private Integer parentDirId;
   private Integer sortNum;
   private String dirDescribe;
   private String productUuid;
   private List<TargetPackageDir> subDir; //子目錄

sql table字段

id	int	
dirname	varchar	
parent_id	
sortnum	int	
dir_describe	
target_package_uuid	


返回結果

<resultMap type="com.mpr.mprsp.rms.service.rms.material.pojo.TargetPackageDir" id="treeDir">
		<result column="id" property="dirId"/>
		<result column="dirname" property="dirName"/>
		<result column="sortnum" property="sortNum"/>
		<result column="dir_describe" property="dirDescribe"/>
		<result column="parent_id" property="parentDirId"/>
		<result column="target_package_uuid" property="productUuid"/>
		<collection property="subDir" column="id" ofType="TargetPackageDir"
<span style="white-space:pre">		</span>select="getSubTreeDir"/>     <!--<span style="font-family: Arial, Helvetica, sans-serif;">property :pojo類子目錄屬性,column:table字段 ,ofTypoe:子目錄的pojo類型 ,select:是查詢子目錄的的sql Id</span><span style="font-family: Arial, Helvetica, sans-serif;">--></span>
</resultMap>


sql語句如下:

<select id="queryAllDirByProUUID" parameterType="string" resultMap="treeDir">
		select
			id,
			dirname,
			parent_id,
			sortnum,
			dir_describe,
			target_package_uuid
		FROM
			T_TARGET_PACKAGE_DIR
		WHERE
			TARGET_PACKAGE_UUID = #{targetPackage_uuid} 
			and parent_id = 0
	</select>
		<!-- 一對多查詢 -->
	<select id="getSubTreeDir" parameterType="string" resultMap="treeDir">
		select 
			   id,
			   dirname,
			   parent_id,
			   sortnum,
			   dir_describe,
			   target_package_uuid
		from t_target_package_dir 
		where parent_id= #{id} 
	</select>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章