json结构:
第一步查询(第一层查询,将第一层的id传递到第二层当条件查询 column=“id”):
<resultMap id="BaseResultMapClass" type="com.kingyon.common.models.shortcut.ShortcutKeyClassBean">
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="title" jdbcType="VARCHAR" property="title"/>
<result column="img" jdbcType="VARCHAR" property="img"/>
<result column="bgColor" jdbcType="VARCHAR" property="bgColor"/>
<result column="describe" jdbcType="VARCHAR" property="describe"/>
<result column="type" jdbcType="BIGINT" property="type"/>
<collection property="functionBeans" ofType="com.kingyon.common.models.shortcut.ShortcutKeyFunctionBean"
select="com.kingyon.core.repository.ShortcutKeyMapper.getShortcutKeyFunction" column="id">
</collection>
</resultMap>
<select id="findShortcutKeyByClassID" resultMap="BaseResultMapClass">
select * from t_shortcut_key_class where id=#{classID} ;
</select>
第二步查询(第二层查询,并将第二层的id传递到第三层当条件查询 column=“funID” 是别名):
<resultMap id="baseShortcutKey" type="com.kingyon.common.models.shortcut.ShortcutKeyFunctionBean">
<id column="id" jdbcType="INTEGER" property="funID"/>
<result column="classID" jdbcType="VARCHAR" property="classID"/>
<result column="describe" jdbcType="VARCHAR" property="describe"/>
<result column="sort" jdbcType="VARCHAR" property="sort"/>
<result column="className" jdbcType="VARCHAR" property="className"/>
<collection property="shortcutKeyBean" ofType="com.kingyon.common.models.shortcut.ShortcutKeyBean"
select="com.kingyon.core.repository.ShortcutKeyMapper.getShortcutKey" column="funID">
</collection>
</resultMap>
<select id="getShortcutKeyFunction" resultMap="baseShortcutKey">
select fun.id as funID,fun.classID,fun.describe,fun.sort from t_shortcut_key_function as fun where fun.classID=#{classID} order by sort DESC ;
</select>
第三步查询(第三层查询):
<resultMap id="shortcutKeyBean" type="com.kingyon.common.models.shortcut.ShortcutKeyBean">
<result property="id" column="keyID"/>
<result property="shortcut" column="shortcut"/>
<result property="details" column="details"/>
</resultMap>
<select id="getShortcutKey" resultMap="shortcutKeyBean">
select * from t_shortcut_key where funID=#{id};
</select>
其实蛮好理解的,就是查询一个,然后把条件传递下步继续查询。。。 使用时调第一层,也就是从高到底。
最后附实体截图,其实看json就可以了:
第一层实体:
第二层实体:
第三层实体:
方式二(推荐)
<collection property="chapterChildBeans"
ofType="com.xx.xx.mode.xx.xxBean">
<id column="cId" property="id"/>
<result column="cName" property="name"/>
</collection>
SELECT c.id,c.name,cc.id as cId,cc.name as cName from t\_chapter c,t\_chapter\_child cc WHERE c.id=cc.chapterID and c.subjectID=#{subjectID}