package com.nnf.controller; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.nnf.model.SecondTGoodsCategory; import com.nnf.model.TGoodsCategory; import com.nnf.service.TGoodsCategoryService; @Controller public class InitController_2 { @Autowired private TGoodsCategoryService tcs; @RequestMapping("init2") public String init(HttpServletRequest request, HttpServletResponse response, HttpSession session) { // 商品一级分类 System.out.println("一级划分:"); List<TGoodsCategory> firstList = tcs.selectByGoodsCategoryParentId(0); for(int i=0;i<firstList.size();i++){ System.out.println(firstList.get(i).getGoodsCategoryName()); } // 商品二级分类 System.out.println(" 二级划分:"); List<TGoodsCategory> clothList = tcs.selectByGoodsCategoryParentId(1); //服装列表 for(int i=0;i<clothList.size();i++){ System.out.println(clothList.get(i).getGoodsCategoryName()); } List<TGoodsCategory> foodList = tcs.selectByGoodsCategoryParentId(2); //食物列表 List<TGoodsCategory> eleProductsList = tcs.selectByGoodsCategoryParentId(3); //电子产品列表 List<TGoodsCategory> electricityList = tcs.selectByGoodsCategoryParentId(4); //电器 List<TGoodsCategory> sportList = tcs.selectByGoodsCategoryParentId(5); //运动列表 // 商品三级分类 System.out.println(" 三级划分:"); //List<TGoodsCategory> clothList = tcs.selectByGoodsCategoryParentId(1); //服装列表 List<TGoodsCategory> clothThirdAllList = new ArrayList<TGoodsCategory>(); List<SecondTGoodsCategory> ss = new ArrayList<SecondTGoodsCategory>(); for (int z = 0; z < clothList.size(); z++) { int goodsCategoryParentId = clothList.get(z).getGoodsCategoryId(); //二级分类的各个ID即三级分类列表的父类ID String cName = clothList.get(z).getGoodsCategoryName(); List<TGoodsCategory> clothThirdList = tcs.selectByGoodsCategoryParentId(goodsCategoryParentId);//单条三级列表 SecondTGoodsCategory s = new SecondTGoodsCategory(); //一个实体类,实体类中的属性分别为 父类ID 父类名称 所包含子类列表 s.setParentId(goodsCategoryParentId); s.setcName(cName); s.setList(clothThirdList); ss.add(s); } for(int i=0;i<ss.size();i++){ System.out.println(ss.get(i).getParentId()); System.out.println(ss.get(i).getcName()); for(int j=0;j<ss.get(i).getList().size();j++){ System.out.println( ss.get(i).getList().get(j).getGoodsCategoryName() ); } } session.setAttribute("ss", ss); return "list"; } } |