com.qfedu.fmmall.entity.CategoryVO
package com.qfedu.fmmall.entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.List;
public class CategoryVO {
@Override
public String toString() {
return "CategoryVO{" +
"categoryId=" + categoryId +
", categoryName='" + categoryName + '\'' +
", categoryLevel=" + categoryLevel +
", parentId=" + parentId +
", categoryIcon='" + categoryIcon + '\'' +
", categorySlogan='" + categorySlogan + '\'' +
", categoryPic='" + categoryPic + '\'' +
", categoryBgColor='" + categoryBgColor + '\'' +
'}';
}
/**
* 主键 分类id主键
*/
@Id
@Column(name = "category_id")
private Integer categoryId;
/**
* 分类名称 分类名称
*/
@Column(name = "category_name")
private String categoryName;
/**
* 分类层级 分类得类型,
* 1:一级大分类
* 2:二级分类
* 3:三级小分类
*/
@Column(name = "category_level")
private Integer categoryLevel;
/**
* 父层级id 父id 上一级依赖的id,1级分类则为0,二级三级分别依赖上一级
*/
@Column(name = "parent_id")
private Integer parentId;
/**
* 图标 logo
*/
@Column(name = "category_icon")
private String categoryIcon;
/**
* 口号
*/
@Column(name = "category_slogan")
private String categorySlogan;
/**
* 分类图
*/
@Column(name = "category_pic")
private String categoryPic;
/**
* 背景颜色
*/
@Column(name = "category_bg_color")
private String categoryBgColor;
private List<CategoryVO> categories;
public List<CategoryVO> getCategories() {
return categories;
}
public void setCategories(List<CategoryVO> categories) {
this.categories = categories;
}
/**
* 获取主键 分类id主键
*
* @return category_id - 主键 分类id主键
*/
public Integer getCategoryId() {
return categoryId;
}
/**
* 设置主键 分类id主键
*
* @param categoryId 主键 分类id主键
*/
public void setCategoryId(Integer categoryId) {
this.categoryId = categoryId;
}
/**
* 获取分类名称 分类名称
*
* @return category_name - 分类名称 分类名称
*/
public String getCategoryName() {
return categoryName;
}
/**
* 设置分类名称 分类名称
*
* @param categoryName 分类名称 分类名称
*/
public void setCategoryName(String categoryName) {
this.categoryName = categoryName;
}
/**
* 获取分类层级 分类得类型,
* 1:一级大分类
* 2:二级分类
* 3:三级小分类
*
* @return category_level - 分类层级 分类得类型,
* 1:一级大分类
* 2:二级分类
* 3:三级小分类
*/
public Integer getCategoryLevel() {
return categoryLevel;
}
/**
* 设置分类层级 分类得类型,
* 1:一级大分类
* 2:二级分类
* 3:三级小分类
*
* @param categoryLevel 分类层级 分类得类型,
* 1:一级大分类
* 2:二级分类
* 3:三级小分类
*/
public void setCategoryLevel(Integer categoryLevel) {
this.categoryLevel = categoryLevel;
}
/**
* 获取父层级id 父id 上一级依赖的id,1级分类则为0,二级三级分别依赖上一级
*
* @return parent_id - 父层级id 父id 上一级依赖的id,1级分类则为0,二级三级分别依赖上一级
*/
public Integer getParentId() {
return parentId;
}
/**
* 设置父层级id 父id 上一级依赖的id,1级分类则为0,二级三级分别依赖上一级
*
* @param parentId 父层级id 父id 上一级依赖的id,1级分类则为0,二级三级分别依赖上一级
*/
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
/**
* 获取图标 logo
*
* @return category_icon - 图标 logo
*/
public String getCategoryIcon() {
return categoryIcon;
}
/**
* 设置图标 logo
*
* @param categoryIcon 图标 logo
*/
public void setCategoryIcon(String categoryIcon) {
this.categoryIcon = categoryIcon;
}
/**
* 获取口号
*
* @return category_slogan - 口号
*/
public String getCategorySlogan() {
return categorySlogan;
}
/**
* 设置口号
*
* @param categorySlogan 口号
*/
public void setCategorySlogan(String categorySlogan) {
this.categorySlogan = categorySlogan;
}
/**
* 获取分类图
*
* @return category_pic - 分类图
*/
public String getCategoryPic() {
return categoryPic;
}
/**
* 设置分类图
*
* @param categoryPic 分类图
*/
public void setCategoryPic(String categoryPic) {
this.categoryPic = categoryPic;
}
/**
* 获取背景颜色
*
* @return category_bg_color - 背景颜色
*/
public String getCategoryBgColor() {
return categoryBgColor;
}
/**
* 设置背景颜色
*
* @param categoryBgColor 背景颜色
*/
public void setCategoryBgColor(String categoryBgColor) {
this.categoryBgColor = categoryBgColor;
}
}
com.qfedu.fmmall.dao.CategoryMapper.java
package com.qfedu.fmmall.dao;
import com.qfedu.fmmall.entity.Category;
import com.qfedu.fmmall.entity.CategoryVO;
import com.qfedu.fmmall.general.GeneralDAO;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface CategoryMapper extends GeneralDAO<Category> {
public List<CategoryVO> selectAllCategories();
}
mappers/CategoryMapper.xml
<?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.qfedu.fmmall.dao.CategoryMapper">
<resultMap id="BaseResultMap" type="com.qfedu.fmmall.entity.Category">
<!--
WARNING - @mbg.generated
-->
<id column="category_id" jdbcType="INTEGER" property="categoryId" />
<result column="category_name" jdbcType="VARCHAR" property="categoryName" />
<result column="category_level" jdbcType="INTEGER" property="categoryLevel" />
<result column="parent_id" jdbcType="INTEGER" property="parentId" />
<result column="category_icon" jdbcType="VARCHAR" property="categoryIcon" />
<result column="category_slogan" jdbcType="VARCHAR" property="categorySlogan" />
<result column="category_pic" jdbcType="VARCHAR" property="categoryPic" />
<result column="category_bg_color" jdbcType="VARCHAR" property="categoryBgColor" />
</resultMap>
<resultMap id="categoryVOMap" type="com.qfedu.fmmall.entity.CategoryVO">
<id column="category_id1" jdbcType="INTEGER" property="categoryId"/>
<result column="category_name1" jdbcType="VARCHAR" property="categoryName"/>
<result column="category_level1" jdbcType="INTEGER" property="categoryLevel"/>
<result column="parent_id1" jdbcType="INTEGER" property="parentId"/>
<result column="category_icon1" jdbcType="VARCHAR" property="categoryIcon"/>
<result column="category_slogan1" jdbcType="VARCHAR" property="categorySlogan"/>
<result column="category_pic1" jdbcType="VARCHAR" property="categoryPic"/>
<result column="category_bg_color1" jdbcType="VARCHAR" property="categoryBgColor"/>
<collection property="categories" ofType="com.qfedu.fmmall.entity.CategoryVO">
<id column="category_id2" jdbcType="INTEGER" property="categoryId"/>
<result column="category_name2" jdbcType="VARCHAR" property="categoryName"/>
<result column="category_level2" jdbcType="INTEGER" property="categoryLevel"/>
<result column="parent_id2" jdbcType="INTEGER" property="parentId"/>
<collection property="categories" ofType="com.qfedu.fmmall.entity.CategoryVO">
<id column="category_id3" jdbcType="INTEGER" property="categoryId"/>
<result column="category_name3" jdbcType="VARCHAR" property="categoryName"/>
<result column="category_level3" jdbcType="INTEGER" property="categoryLevel"/>
<result column="parent_id3" jdbcType="INTEGER" property="parentId"/>
</collection>
</collection>
</resultMap>
<!-- 联合查询-->
<select id="selectAllCategories" resultMap="categoryVOMap">
select
c1.category_id 'category_id1',
c1.category_name 'category_name1',
c1.category_level 'category_level1',
c1.parent_id 'parent_id',
c1.category_icon 'category_icon1',
c1.category_slogan 'category_slogan1',
c1.category_pic 'category_pic1',
c1.category_bg_color 'category_bg_color1',
c2.category_id 'category_id2',
c2.category_name 'category_name2',
c2.category_level 'category_level2',
c2.parent_id 'parent_id2',
c3.category_id 'category_id3',
c3.category_name 'category_name3',
c3.category_level 'category_level3',
c3.parent_id 'parent_id3'
from category c1
inner join category c2
on c2.parent_id = c1.category_id
inner join category c3
on c3.parent_id = c2.parent_id
where c1.category_level = 1
</select>
</mapper>
总结
复杂度 超出自己的预期 和 想象