级联查询

<resultMap id="BaseResultMap" type="com.beta.cas.model.AuthModel">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="status" property="status" />
        <result column="levels" property="levels" />
        <result column="parent_id" property="parentId" />
        <result column="url" property="url" />
        <result column="show" property="show" />
        <result column="icon" property="icon" />
        <result column="sort" property="sort" />
        <result column="permission" property="permission" />
        <result column="creator_id" property="creatorId" />
        <result column="creator" property="creator" />
        <result column="create_time" property="createTime" />
        <result column="modify_id" property="modifyId" />
        <result column="modify_by" property="modifyBy" />
        <result column="modify_time" property="modifyTime" />
        <result column="app_id" property="appId" />
        <collection property="children" ofType="com.beta.cas.model.AuthModel" select="selectByParentId" column="id"></collection>
    </resultMap>
    <select id="findById" resultMap="BaseResultMap" parameterType="long">
        select * from auth where id = #{id}
    </select>
    <select id="findByAppId" resultMap="BaseResultMap">
        select * from auth where app_id = #{appId} and levels = #{levels} order by id
    </select>
    <select id="selectByParentId" resultMap="BaseResultMap">
        select am.* from auth am  where am.parent_id=#{parentId}
    </select>

如果返回一个对象,可以增加

<association property="parent" javaType="com.beta.cas.model.AuthModel" select="findById" column="parent_id"></association>

如果返回一个集合,则必须去掉

否则出现高度递归情况

posted @ 2018-04-13 18:22  yangfei969  阅读(237)  评论(0编辑  收藏  举报