23分布式电商项目 - 商品分类管理(列表实现)

简介: 23分布式电商项目 - 商品分类管理(列表实现)

需求分析

实现三级商品分类列表查询功能

进入页面首先显示所以一级分类,效果如下:

点击列表行的查询下级按钮,进入下级分类列表,同时更新面包屑导航

再次点击表行的查询下级按钮,进入三级分类列表,因为三级分类属于最后一级,所以在列表中不显示查询下级按钮,同时更新面包屑导航

表结构分析

tb_item_cat 商品分类表

列表实现

1.后端代码

修改 pinyougou-sellergoods-interface 工程ItemCatService 接口,新增方法定义

/**
* 根据上级 ID 返回列表
* @return
*/
public List<TbItemCat> findByParentId(Long parentId);

修改 pinyougou-sellergoods-interface 工程ItemCatServiceImpl ,实现方法

/**
* 根据上级 ID 查询列表
*/
@Override
public List<TbItemCat> findByParentId(Long parentId) {
  TbItemCatExample example1=new TbItemCatExample();
  Criteria criteria1 = example1.createCriteria();
  criteria1.andParentIdEqualTo(parentId);
  return itemCatMapper.selectByExample(example1);
}

修改 pinyougou-manager-web 的 ItemCatController.java

/**
* 根据上级 ID 查询列表
* @param parentId
* @return
*/
@RequestMapping("/findByParentId")
  public List<TbItemCat> findByParentId(Long parentId){
  return itemCatService.findByParentId(parentId);
}

2.前端代码

(1)修改 itemCatService.js

//根据上级 ID 查询下级列表
this.findByParentId=function(parentId){
  return $http.get('../itemCat/findByParentId.do?parentId='+parentId);
}

(2)修改 itemCatController.js

//根据上级 ID 显示下级列表
$scope.findByParentId=function(parentId){
itemCatService.findByParentId(parentId).success(
  function(response){
    $scope.list=response;
  }
);
}

(3)修改 item_cat.html

引入 JS

<script type="text/javascript" src="../plugins/angularjs/angular.min.js"> </script>
<script type="text/javascript" src="../js/base.js"> </script>
<script type="text/javascript" src="../js/service/itemCatService.js"> </script>
<script type="text/javascript" src="../js/controller/baseController.js"> </script>
<script type="text/javascript" src="../js/controller/itemCatController.js"> </script>

指令定义

<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="itemCatController" ng-init="findByParentId(0)">

循环列表

<tr ng-repeat="entity in list">
  <td><input type="checkbox" ></td>  
  <td>{{entity.id}}</td>
  <td>{{entity.name}}</td>  
  <td>{{entity.typeId}}</td>  
  <td class="text-center">  
    <button type="button" class="btn bg-olive btn-xs" ng-click="findByParentId(entity.id)">查询下级</button>  
    <button type="button" class="btn bg-olive btn-xs" data-toggle="modal" data-target="#editModal" >修改</button> 
  </td>
</tr>



目录
相关文章
|
2月前
|
NoSQL 调度 Redis
19- 你的项目中哪里用到了分布式锁
在一个项目中,为解决集群环境下SpringTask定时任务的重复执行问题,采用了Redis实现分布式锁来管理任务调度,防止资源浪费。后来因任务量和执行规则增加,以及单节点效率限制,系统改用XXL-JOB,分布式锁不再使用。
39 2
|
2月前
|
缓存 NoSQL Java
分布式项目中锁的应用(本地锁-_redis【setnx】-_redisson-_springcache)-fen-bu-shi-xiang-mu-zhong-suo-de-ying-yong--ben-de-suo--redissetnx-springcache-redisson(一)
分布式项目中锁的应用(本地锁-_redis【setnx】-_redisson-_springcache)-fen-bu-shi-xiang-mu-zhong-suo-de-ying-yong--ben-de-suo--redissetnx-springcache-redisson
75 0
|
2月前
|
SpringCloudAlibaba Java 持续交付
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
315 0
|
3天前
|
消息中间件 Java 中间件
如何在Java项目中实现分布式事务管理
如何在Java项目中实现分布式事务管理
|
2月前
|
XML NoSQL Java
Java单体项目和分布式项目中的锁
Java单体项目和分布式项目中的锁 Java单体项目和分布式项目中的锁
51 2
|
2月前
|
缓存 NoSQL Redis
分布式项目中锁的应用(本地锁-_redis【setnx】-_redisson-_springcache)-fen-bu-shi-xiang-mu-zhong-suo-de-ying-yong--ben-de-suo--redissetnx-springcache-redisson(二)
分布式项目中锁的应用(本地锁-_redis【setnx】-_redisson-_springcache)-fen-bu-shi-xiang-mu-zhong-suo-de-ying-yong--ben-de-suo--redissetnx-springcache-redisson
48 0
|
2月前
|
存储 NoSQL 文件存储
C++ 哈希表企业级项目运用---淘宝分布式文件系统
C++ 哈希表企业级项目运用---淘宝分布式文件系统
|
9天前
|
NoSQL Redis
redis分布式锁redisson
底层会尝试去加锁,如果加锁失败,会睡眠,自旋加锁,直到获取到锁为止。
15 1
|
6天前
|
消息中间件 NoSQL Java
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
Redis系列学习文章分享---第六篇(Redis实战篇--Redis分布式锁+实现思路+误删问题+原子性+lua脚本+Redisson功能介绍+可重入锁+WatchDog机制+multiLock)
26 0
|
7天前
|
NoSQL 算法 Java
技术好文:Redis实现分布式锁的7种方案
技术好文:Redis实现分布式锁的7种方案