<resultMap id="BaseResultMap2" type="com.pojo.CaCategoryTreeVo"> <id column="id" jdbcType="INTEGER" property="id"/> <result column="title" jdbcType="VARCHAR" property="title"/> <result column="parentid" jdbcType="INTEGER" property="parentId"/> <collection property="children" select="getMenus" column="id" ofType="com.pojo.CaCategoryTreeVo" javaType="java.util.ArrayList"> </collection> </resultMap> <select id="getMenus" resultMap="BaseResultMap2" parameterType="java.lang.Integer"> SELECT id ,title,parentid FROM ca_category WHERE category_type=1 and parentid=#{_parameter} </select> <select id="selectTree" resultMap="BaseResultMap2" parameterType="java.lang.Integer"> <if test="id !=null "> SELECT id ,title,parentid FROM ca_category WHERE category_type =1 and id = #{id} </if> <if test="id ==null "> SELECT id ,title,parentid FROM ca_category WHERE category_type = 1 AND parentid in ( SELECT id FROM ca_category WHERE category_type = 1 AND parentid = 0 ) </if> </select>