mapper配置
- 结果集配置
<resultMap id="MenuContents" type="com.phfund.micro.dto.DmspIndexMenuDTO">
<result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
<result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
<result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
<collection property="IndexMenu" ofType="com.phfund.micro.dto.DmspIndexMenuDTO" column="MENU_CODE" select="queryMenuChildContents"/>
</resultMap>
<resultMap id="MenuchildMap" type="com.phfund.micro.dto.DmspIndexMenuDTO">
<result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
<result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
<result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
<collection property="IndexMenu" ofType="com.phfund.micro.dto.DmspIndexMenuDTO" column="MENU_CODE" select="queryMenuSonContents"/>
</resultMap>
<resultMap id="sonContentsMenuMap" type="com.phfund.micro.dto.DmspIndexMenuDTO">
<result column="MENU_CODE" jdbcType="VARCHAR" property="menuCode" />
<result column="MENU_NAME" jdbcType="VARCHAR" property="menuName" />
<result column="MENU_FLAG" jdbcType="VARCHAR" property="menuflag" />
</resultMap>
2.SQL语句配置
<select id="queryMenuContents" resultMap="MenuContents">
select MENU_CODE,MENU_NAME,'0' as MENU_FLAG from DMSP_INDEX_MENU where PARENT_MENU_CODE='root' order by MENU_ORDER
</select>
<select id="queryMenuChildContents" resultMap="MenuchildMap">
select MENU_CODE,MENU_NAME ,'0' as MENU_FLAG,MENU_ORDER from DMSP_INDEX_MENU where PARENT_MENU_CODE=#{menuCode,jdbcType=VARCHAR}
</select>
<select id="queryMenuSonContents" resultMap="sonContentsMenuMap">
select MENU_CODE,MENU_NAME ,'0' as MENU_FLAG,MENU_ORDER from DMSP_INDEX_MENU where PARENT_MENU_CODE=#{menuCode,jdbcType=VARCHAR}
</select>
3.部分解释
< collection property=“IndexMenu” ofType=“com.phfund.micro.dto.DmspIndexMenuDTO” column=“MENU_CODE” select=“queryMenuChildContents”/>
property:表示对应实体类中的属性 List<?> 类型
ofType:实体类
column:结果集中的字段,也就是查询所对应的参数值
select :对应的查询语句 queryMenuChildContents为对应语句的id