1.pojo类
public class Category implements Serializable{ private String cid; //分类主键 private String cname; //分类名 private Category parent; //父分类,是根据pid的自连接对象,一个二级分类只有一个一级分类 private String desc; //描述 private Listchildren; //子分类,一个一级分类可能有多个二级分类,而二级分类无子分类 //setter and getter method...}
2.dao接口
public interface CategoryDao { public Category load(String cid) throws SQLException; public ListfindByParent(String pid) throws SQLException; public List findParent() throws SQLException; public void add(Category category) throws SQLException; public void edit(Category category) throws SQLException; public int findChildrenByParent(String pid) throws SQLException; public void delete(String cid) throws SQLException;}
3.Mapper映射文件(切记实体类里的toString方法里边去掉类型为List的属性,要不然打印时会出现死循环的)。