项目中遇到一个需求:需要三级数据的展示
我的做法:
首先编写查出各级分类的sql(根据自己的需求和表数据)
<select id="selectOneLevel" resultMap="TCategoryResult">
SELECT * from t_category WHERE category_level = #{categoryLevel}
</select>
<select id="selectNextLevel" resultMap="TCategoryResult">
SELECT * from t_category WHERE parent_code = #{parentCode} AND category_level = #
{categoryLevel}
</select>
然后在接口中处理强求(逻辑如下)
List<TCategory> tCategories = tCategoryService.selectOneLevel("0");
for (TCategory tCategory : tCategories) {
String categoryCode = tCategory.getCategoryCode();
List<TCategory> children = tCat