IMCategoryMapper.xml 2.6 KB
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.sibu.orderHelper.integral.dao.IMCategoryDao">
	
    <!-- 查询父类分类和子类分类
    <select id="listImCategory" resultMap="listIMCategory" useCache="true" statementType="PREPARED">
        SELECT
			g.im_category_id, g.name, g.image_url, g.sort_index, 
			g2.im_category_id cim_category_id, g2.name cim_name, g2.image_url cim_image_url, g2.sort_index cim_index  
		FROM
			im_category g left join im_category g2 ON g2.child_category_id = g.im_category_id
		WHERE
			g.child_category_id IS NULL and g.delete_flag = 1
    </select>
    -->
    
    <select id="listImCategory" resultMap="listParentIMCategory" useCache="true">
    	SELECT
			g.im_category_id, g.name, g.image_url, g.sort_index, g.type_id, g.category_type 
		FROM
			im_category g
		WHERE
			g.delete_flag = 1 and (g.child_category_id IS NULL or g.child_category_id = '') 
		order by g.sort_index asc 
    </select>

	<select id="listChildrenImCategory" parameterType="String" resultMap="listParentIMCategory" useCache="true">
    	SELECT
			g.im_category_id, g.name, g.image_url, g.sort_index, g.type_id, g.category_type 
		FROM
			im_category g
		WHERE
			g.child_category_id = #{categoryId} and g.delete_flag = 1 
		order by g.sort_index asc 
    </select>
	
	<resultMap type="IMCategoryBean" id="listParentIMCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <result column="type_id" property="typeId" />
        <result column="category_type" property="categoryType" />
    </resultMap>

    <resultMap type="IMCategoryBean" id="listIMCategory">
        <result column="im_category_id" property="imCategoryId" />
        <result column="name" property="name" />
        <result column="image_url" property="imageUrl" />
        <result column="sort_index" property="sortIndex" />
        <collection property="childs" column="child_category_id" ofType="IMCategoryBean">
            <result property="imCategoryId" column="cim_category_id" javaType="String" jdbcType="VARCHAR"/>
            <result property="name" column="cim_name" javaType="String" jdbcType="VARCHAR"/>
            <result property="imageUrl" column="cim_image_url" javaType="String" jdbcType="VARCHAR"/>
            <result property="sortIndex" column="cim_index" javaType="Integer" jdbcType="INTEGER"/>    
        </collection>
    </resultMap>
</mapper>