废话不多说,直接贴代码:

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三级菜单分类查询详解相关推荐

  1. java中定义score方法_elasticsearch 自定义 script score JavaAPI查询详解

    一:自定义score的应用场景 先打个比方,比如新产品上架了,我想让最新上架的产品搜索时候,排在前面,怎么办呢?很简单按时间排序.嗯这种方法很好实现. 但下面又有个需求,比如我要求排序中上架时间的比重 ...

  2. java中String s=abc及String s=new String(abc)详解

    java中String s="abc"及String s=new String("abc")详解 1.   栈(stack)与堆(heap)都是Java用来在R ...

  3. java中printf,print,println,区别及用法详解

    此题是蓝桥杯的一道竞赛试题,在编写程序时,遇到了printf的用法,不是很熟悉,特此总结一下. 以下是对Java中print.printf.println的区别进行了详细的分析介绍,需要的朋友可以过来 ...

  4. java中创建线程的四种方式及线程池详解

    众所周知,我们在创建线程时有四种方法可以用,分别是: 1.继承Thread类创建线程 2.实现Runnable接口创建线程 3.使用Callable和Future创建线程 4.使用线程池创建(使用ja ...

  5. java中循环语句_Java语法基础之循环结构语句详解

    一.循环结构 循环语句可以在满足循环条件的情况下,反复执行某一段代码,这段被重复执行的代码被称为循环体语句,当反复执行这个循环体时,需要在合适的时候把循环判断条件修改为false,从而结束循环,否则循 ...

  6. java中final是修饰符么_Java final修饰符详解

    final 在 Java 中的意思是最终,也可以称为完结器,表示对象是最终形态的,不可改变的意思.final 应用于类.方法和变量时意义是不同的,但本质是一样的,都表示不可改变. 使用 final 关 ...

  7. Java中的String数据类型,String类(字符串)详解

    目录 第一章.String概述 1)String是什么 2)String长什么样 3)String的构造方法(声明方式) 第二章.String类的详解 1)String底层是什么 2)字符串存储的内存 ...

  8. java中elapseTime设置新时间,Jmeter系列(44)- 详解 Elapsed time、Latency、Connect Time的含义...

    如果你想从头学习Jmeter,可以看看这个系列的文章哦 前言 在 Jmeter 中一些专业名词我们是需要提前认知的,如下 Elapsed time Latency Connect Time ===== ...

  9. java中document解析jsp,JSP基于dom解析xml实例详解

    本文实例讲述了JSP基于dom解析xml的方法.分享给大家供大家参考,具体如下: 初次学习用dom操作xml文件,有很多不足之处,牛人多给点建议,练习时我没对中文做乱码处理,也没做验证哦!O(∩_∩) ...

最新文章

  1. 美团高级技术专家:DDD 在旅游电商架构演进中的实践
  2. fft 估计载波频率程序_OFDM信道估计和仿真
  3. CosmoMC第一次测试
  4. 【sklearn学习】逻辑回归
  5. flink的watermark简单理解
  6. linux下的raid及mdadm的命令详解
  7. 表格(table)不被撑开的解决办法
  8. Java 清除指定目录文件夹下文件
  9. 统一沟通-技巧-10-Lync-公网证书-Go Daddy-Buy
  10. 深度装机大师一键重装_深度一键重装系统软件
  11. java 死链检测_网站死链检测工具/网站地图生成工具
  12. 矩阵连乘c语言实验报告,矩阵连乘实验报告.docx
  13. python模拟类蠕虫--蠕虫初探
  14. Arcgis报错 ERROR 999999的解决方法汇总
  15. Java并发编程:自己动手写一把可重入锁
  16. SQL语句查询出现异常,SQL语句:*** 给定关键字不在字典中。
  17. Python爬虫--- 1.5 爬虫实践: 获取百度贴吧内容
  18. 小程序战局最新动态!这些你应该知道
  19. xray 被动_google搜索爬取xray被动扫描
  20. linux终端打英文间隔太大,解决vs code 内置终端,字体间隔过大问题。(linux centos7成功)...

热门文章

  1. 虚拟现实技术利用计算机,虚拟现实技术在计算机专业教学中的应用思考
  2. java中线性结构的例子_java数据结构--线性结构
  3. 浅谈auto与decltype函数的区别
  4. 数据库系统内部体系结构与外部体系结构
  5. mysql AUTO_INC 是否锁_AUTO-INC锁的一些思考
  6. NOIP模拟测试14「旋转子段·走格子·柱状图」
  7. 「PKUWC2018」Slay the Spire
  8. Codeforces 1058 D. Vasya and Triangle 分解因子
  9. [P1580] yyy loves Easter_Egg I
  10. 网络15软工个人作业5——软件工程总结