日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java中菜单分几级_JavaWeb三级菜单分类查询详解

發布時間:2023/12/2 java 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java中菜单分几级_JavaWeb三级菜单分类查询详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

廢話不多說,直接貼代碼:

dao層代碼:

mapper:

ListselectByParentId(Integer id);

mapper.xml

select

from easybuy_product_category

where parentId = #{parentId,jdbcType=INTEGER}

Test:

import cn.hd.entity.ProductCategory;

import cn.hd.mapper.ProductCategoryMapper;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext_dao.xml")

public class productCategoryTest {

@Resource(name = "productCategoryMapper")

private ProductCategoryMapper productCategoryMapper;

@Test

public void fun(){

ListproductCategories = productCategoryMapper.selectByParentId(0);

System.out.println(productCategories);

}

}

service:

ListgetProductCategoryList();

serviceImpl:

package cn.hd.service.impl;

import cn.hd.entity.ProductCategory;

import cn.hd.mapper.ProductCategoryMapper;

import cn.hd.query_vo.productCategoryQueryVo;

import cn.hd.service.ProductCategoryService;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.util.ArrayList;

import java.util.List;

@Service("productCategoryServiceImpl")

public class ProductCategoryServiceImpl implements ProductCategoryService {

@Resource(name = "productCategoryMapper")

private ProductCategoryMapper productCategoryMapper;

@Override

public ListgetProductCategoryList() {

ListproductCategoryQueryVoList = new ArrayList<>();

ListproductCategory1 = productCategoryMapper.selectByParentId(0);

for (ProductCategory p1 : productCategory1) {

productCategoryQueryVo productCategoryQueryVo = new productCategoryQueryVo();

/*一級分類中的二級分類*/

ListproductCategory2 = productCategoryMapper.selectByParentId(p1.getId());

for (ProductCategory p2 : productCategory2) {

productCategoryQueryVo productCategoryQueryVo1 = new productCategoryQueryVo();

ListproductCategories3 = productCategoryMapper.selectByParentId(p2.getId());

for (ProductCategory p3:productCategories3) {

productCategoryQueryVo productCategoryQueryVo2 = new productCategoryQueryVo();

productCategoryQueryVo2.setProductCategories(p3);

productCategoryQueryVo1.getProductCategoryVoList().add(productCategoryQueryVo2);

}

productCategoryQueryVo1.setProductCategories(p2);

productCategoryQueryVo.getProductCategoryVoList().add(productCategoryQueryVo1);

}

/*封裝一級分類 本身*/

productCategoryQueryVo.setProductCategories(p1);

productCategoryQueryVoList.add(productCategoryQueryVo);

}

return productCategoryQueryVoList;

}

}

Test:

import cn.hd.service.ProductCategoryService;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.test.context.ContextConfiguration;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:applicationContext_service.xml")

public class productCategoryTest {

@Resource(name = "productCategoryServiceImpl")

private ProductCategoryService productCategoryService;

@Test

public void fun(){

productCategoryService.getProductCategoryList();

}

}

Controller:

package cn.hd.controller;

import cn.hd.query_vo.productCategoryQueryVo;

import cn.hd.service.ProductCategoryService;

import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

import java.util.List;

@Controller

public class ProductCategoryController {

@Resource(name = "productCategoryServiceImpl")

private ProductCategoryService productCategoryService;

@RequestMapping("/index")

public String index(Model model){

ListproductCategoryVoList = productCategoryService.getProductCategoryList();

model.addAttribute("productCategoryVoList",productCategoryVoList);

return "jsp/pre/index.jsp";

}

}

JSP

數據庫設計

總結

以上是生活随笔為你收集整理的java中菜单分几级_JavaWeb三级菜单分类查询详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。