查询自关联表,并将查询到的数据在页面显示
该处以ssm框架为例
表结构
实体类
public class Category {
private String cid;
private String cname;
private Category pid;//父分类
private String desc;
private List<Category> categoryList;//子分类
}
后面还有get、ser和toString方法就不在代码中展示了,记得自己加上去呦
扩展类
public class CategoryCustom extends Category {
private List<Category> category;
}
同样也有get、ser和toString方法
dao层
import com.hlwxy.ssm.model.Category;
import com.hlwxy.ssm.model.CategoryCustom;
import java.util.List;
public interface CategoryMapper {
//查询所有一级分类
public List<CategoryCustom> findCategory();
//通过父分类查询子分类
public List<Category> findCategoryByPid(CategoryCustom categoryCustom);
}
<!--查询所有一级分类-->
<select id="findCategory" parameterType="com.hl