13分布式电商项目 - 品牌管理模块

简介: 13分布式电商项目 - 品牌管理模块

代码已上传到GitHub

地址:https://github.com/ylw-github/pingyougou.git

版本号:05dade77bb17941f980dcce99567cfdd8d380018

先看一下项目运行的效果:

表现层代码:

brand.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>品牌管理</title>
<meta
  content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
  name="viewport">
<link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="../plugins/adminLTE/css/AdminLTE.css">
<link rel="stylesheet"
  href="../plugins/adminLTE/css/skins/_all-skins.min.css">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../plugins/angularjs/pagination.css">
<script src="../plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/angularjs/angular.min.js"></script>
<script src="../plugins/angularjs/pagination.js"></script>
<script type="text/javascript">
  //定义模块
  var app = angular.module("pyg", [ 'pagination' ]);
  //定义控制器
  app.controller(
      "brandController",
      function($scope, $http) {
        //查询所有函数
        $scope.findAll = function() {
          //使用内置服务发送请求
          $http.get("../brand/findAll").success(function(data) {
            $scope.list = data;
          })
        };
        //重新加载列表 数据
        $scope.reloadList = function() {
          //切换页码
          $scope.search($scope.paginationConf.currentPage,
              $scope.paginationConf.itemsPerPage);
        }
        //分页控件配置
        $scope.paginationConf = {
          currentPage : 1,
          totalItems : 10,
          itemsPerPage : 10,
          perPageOptions : [ 10, 20, 30, 40, 50 ],
          onChange : function() {
            $scope.reloadList();//重新加载
          }
        };
        //分页
        $scope.findPage = function(page, rows) {
          $http.get('../brand/findPage?page=' + page + '&rows='+ rows).success(function(data) {
            $scope.list = data.rows;
            $scope.paginationConf.totalItems = data.total;//更新总记录数
          });
        };
        //添加函数
        $scope.add = function(){
          //定义方法名
          var methodName = "add";
          //判断如果id存在,是修改
          if($scope.entity.id!=null){
            methodName="update";
          }         
          //内置服务发送请求
          $http.post("../brand/"+methodName,$scope.entity).success(function(data){
            //判断
            if(data.success){
              //刷新
              $scope.reloadList();
            }else{
              alert(data.message);
            }
          })
        };
        //根据id查询品牌
        $scope.findOne = function(id){
          //发送请求
          $http.get("../brand/findOne?id="+id).success(
            function(data){
              $scope.entity = data;
            }   
          )
        }
        //初始化对象
        $scope.searchEntity = {};
        //条件查询方法
        $scope.search = function(page,rows){
          //发送条件查询请求
          $http.post("../brand/search?page="+page+"&rows="+rows,$scope.searchEntity).success(
            function(data){
              $scope.list = data.rows;
              $scope.paginationConf.totalItems = data.total;//更新总记录数
            }   
          )
        }
      })
</script>
</head>
<body ng-app="pyg" ng-controller="brandController"
  class="hold-transition skin-red sidebar-mini">
  <!-- .box-body -->
  <div class="box-header with-border">
    <h3 class="box-title">品牌管理</h3>
  </div>
  <div class="box-body">
    <!-- 数据表格 -->
    <div class="table-box">
      <!--工具栏-->
      <div class="pull-left">
        <div class="form-group form-inline">
          <div class="btn-group">
            <button type="button" class="btn btn-default" title="新建"
              data-toggle="modal" ng-click="entity={}" data-target="#editModal">
              <i class="fa fa-file-o"></i> 新建
            </button>
            <button type="button" class="btn btn-default" title="删除">
              <i class="fa fa-trash-o"></i> 删除
            </button>
            <button type="button" class="btn btn-default" title="刷新"
              onclick="window.location.reload();">
              <i class="fa fa-refresh"></i> 刷新
            </button>
          </div>
        </div>
      </div>
      <div class="box-tools pull-right">
        品牌名:<input type="text" ng-model="searchEntity.name" >
        首字母:<input type="text" ng-model="searchEntity.firstChar" >
        <button ng-click="reloadList()">查询</button>
        <div class="has-feedback"></div>
      </div>
      <!--工具栏/-->
      <!--数据列表-->
      <table id="dataList"
        class="table table-bordered table-striped table-hover dataTable">
        <thead>
          <tr>
            <th class="" style="padding-right: 0px"><input id="selall"
              type="checkbox" class="icheckbox_square-blue"></th>
            <th class="sorting_asc">品牌ID</th>
            <th class="sorting">品牌名称</th>
            <th class="sorting">品牌首字母</th>
            <th class="text-center">操作</th>
          </tr>
        </thead>
        <tbody>
          <tr ng-repeat="entity in list">
            <td><input type="checkbox"></td>
            <td>{{entity.id}}</td>
            <td>{{entity.name}}</td>
            <td>{{entity.firstChar}}</td>
            <td class="text-center">
              <button type="button" class="btn bg-olive btn-xs"
                data-toggle="modal" ng-click="findOne(entity.id)" data-target="#editModal">修改</button>
            </td>
          </tr>
        </tbody>
      </table>
      <!--数据列表/-->
      <tm-pagination conf="paginationConf"></tm-pagination>
    </div>
    <!-- 数据表格 /-->
  </div>
  <!-- /.box-body -->
  <!-- 编辑窗口 -->
  <div class="modal fade" id="editModal" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal"
            aria-hidden="true">×</button>
          <h3 id="myModalLabel">品牌编辑</h3>
        </div>
        <div class="modal-body">
          <table class="table table-bordered table-striped" width="800px">
            <tr>
              <td>品牌名称</td>
              <td><input class="form-control" ng-model="entity.name" placeholder="品牌名称">
              </td>
            </tr>
            <tr>
              <td>首字母</td>
              <td><input class="form-control" ng-model="entity.firstChar" placeholder="首字母"></td>
            </tr>
          </table>
        </div>
        <div class="modal-footer">
          <button class="btn btn-success" data-dismiss="modal"
            aria-hidden="true" ng-click="add()">保存</button>
          <button class="btn btn-default" data-dismiss="modal"
            aria-hidden="true">关闭</button>
        </div>
      </div>
    </div>
  </div>
</body>
</html>
BrandController
package com.pyg.manager.controller;
import java.util.List;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.dubbo.config.annotation.Reference;
import com.pyg.manager.service.BrandService;
import com.pyg.pojo.TbBrand;
import com.pyg.utils.PageResult;
import com.pyg.utils.PygResult;
@RestController
@RequestMapping("/brand")
public class BrandController {
  //注入远程服务对象
  @Reference(timeout=10000000,retries=2)
  private BrandService brandService;
  /**
   * 需求:查询所有品牌数据
   */
  @RequestMapping("/findAll")
  public List<TbBrand> findAll(){
    //调用远程服务对象方法
    List<TbBrand> list = brandService.findAll();
    return list;
  }
  /**
   * 需求:分页展示品牌列表
   * 参数:Integer page,Integer rows
   * 返回值:分页包装类对象PageResult
   */
  @RequestMapping("/findPage")
  public PageResult findPage(Integer page,Integer rows){
    //调用远程服务对象
    PageResult result = brandService.findPage(page, rows);
    return result;
  }
  /**
   * 需求:添加品牌数据
   * 参数:TbBrand brand
   * 返回值:PygResult
   * 
   */
  @RequestMapping("/add")
  public PygResult add(@RequestBody TbBrand brand){
    //调用远程服务
    PygResult result = brandService.add(brand);
    return result;
  }
  /**
   * 需求:根据id查询品牌数据
   * 请求:../brand/findOne?id=?
   * 参数:Long id
   * 返回值:TbBrand
   */
  @RequestMapping("/findOne")
  public TbBrand findOne(Long id){
    //调用远程服务
    TbBrand brand = brandService.findOne(id);
    return brand;
  }
  /**
   * 需求:更新品牌数据
   * 请求:/brand/update
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  @RequestMapping("/update")
  public PygResult update(@RequestBody TbBrand brand){
    //调用远程服务
    PygResult result = brandService.update(brand);
    return result;
  }
  /**
   * 需求:品牌条件查询
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  @RequestMapping("search")
  public PageResult search(@RequestBody TbBrand brand,
      @RequestParam(defaultValue="1") Integer page,
      @RequestParam(defaultValue="10") Integer rows){
    //调用服务层条件查询方法
    PageResult result = brandService.findBrandByPage(brand, page, rows);
    return result;
  }
}

服务层代码

BrandService
package com.pyg.manager.service;
import java.util.List;
import com.pyg.pojo.TbBrand;
import com.pyg.utils.PageResult;
import com.pyg.utils.PygResult;
public interface BrandService {
  /**
   * 需求:查询所有品牌数据
   */
  public List<TbBrand> findAll();
  /**
   * 需求:分页展示品牌列表
   * 参数:Integer page,Integer rows
   * 返回值:分页包装类对象PageResult
   */
  public PageResult findPage(Integer page, Integer rows);
  /**
   * 需求:添加品牌数据
   * 参数:TbBrand brand
   * 返回值:PygResult
   * 
   */
  public PygResult add(TbBrand brand);
  /**
   * 需求:根据id查询品牌数据
   * 参数:Long id
   * 返回值:TbBrand
   */
  public TbBrand findOne(Long id);
  /**
   * 需求:更新品牌数据
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  public PygResult update(TbBrand brand);
  /**
   * 需求:品牌条件查询
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  public PageResult findBrandByPage(TbBrand brand, Integer page, Integer rows);
}
BrandServiceImpl
package com.pyg.manager.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.pyg.manager.service.BrandService;
import com.pyg.mapper.TbBrandMapper;
import com.pyg.pojo.TbBrand;
import com.pyg.pojo.TbBrandExample;
import com.pyg.pojo.TbBrandExample.Criteria;
import com.pyg.utils.PageResult;
import com.pyg.utils.PygResult;
@Service
public class BrandServiceImpl implements BrandService{
  //注入mapper接口代理对象
  @Autowired
  private TbBrandMapper brandMapper;
  @Override
  public List<TbBrand> findAll() {
    //创建example对象
    TbBrandExample example = new TbBrandExample();
    // 查询
    List<TbBrand> list = brandMapper.selectByExample(example);
    return list;
  }
  /**
   * 需求:分页展示品牌列表
   * 参数:Integer page,Integer rows
   * 返回值:分页包装类对象PageResult
   */
  public PageResult findPage(Integer page, Integer rows) {
    //创建example对象
    TbBrandExample example = new TbBrandExample();
    // 使用插件设置分页
    PageHelper.startPage(page, rows);
    //查询品牌数据
    //List={page[total,pagesie],list}
    List<TbBrand> list = brandMapper.selectByExample(example);
    //创建pageINfo对象,获取查询分页数据
    PageInfo<TbBrand> pageInfo = new PageInfo<TbBrand>(list);
    return new PageResult(pageInfo.getTotal(), list);
  }
  /**
   * 需求:添加品牌数据
   * 参数:TbBrand brand
   * 返回值:PygResult
   * 
   */
  public PygResult add(TbBrand brand) {
    try {
      //保存品牌数据
      brandMapper.insertSelective(brand);
      //保存成功
      return new PygResult(true, "保存成功");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      //保存成功
      return new PygResult(false, "保存失败");
    }
  }
  /**
   * 需求:根据id查询品牌数据
   * 参数:Long id
   * 返回值:TbBrand
   */
  public TbBrand findOne(Long id) {
    //根据id查询品牌数据
    TbBrand brand = brandMapper.selectByPrimaryKey(id);
    return brand;
  }
  /**
   * 需求:更新品牌数据
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  public PygResult update(TbBrand brand) {
    // TODO Auto-generated method stub
    try {
      brandMapper.updateByPrimaryKeySelective(brand);
      //保存成功
      return new PygResult(true, "修改成功");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      //保存成功
      return new PygResult(false, "修改失败");
    }
  }
  /**
   * 需求:品牌条件查询
   * 参数:TbBrand brand
   * 返回值:PygResult
   */
  public PageResult findBrandByPage(TbBrand brand, Integer page, Integer rows) {
    // 创建example对象
    TbBrandExample example = new TbBrandExample();
    //创建criteria对象
    Criteria createCriteria = example.createCriteria();
    //设置参数
    //判断参数是否存在
    if(brand.getName()!=null && !"".equals(brand.getName())){
      //模糊查询
      createCriteria.andNameLike("%"+brand.getName()+"%");
    }
    if(brand.getFirstChar()!=null && !"".equals(brand.getFirstChar())){
      createCriteria.andFirstCharEqualTo(brand.getFirstChar());
    }
    //查询之前,必须设置分页
    PageHelper.startPage(page,rows);
    //执行查询
    List<TbBrand> list = brandMapper.selectByExample(example);
    //创建PageINfo,获取分页数据
    PageInfo<TbBrand> pageInfo = new PageInfo<TbBrand>(list);
    //返回分页包装对象
    return new PageResult(pageInfo.getTotal(), list);
  }
}



目录
相关文章
|
4月前
|
NoSQL 调度 Redis
19- 你的项目中哪里用到了分布式锁
在一个项目中,为解决集群环境下SpringTask定时任务的重复执行问题,采用了Redis实现分布式锁来管理任务调度,防止资源浪费。后来因任务量和执行规则增加,以及单节点效率限制,系统改用XXL-JOB,分布式锁不再使用。
56 2
|
4月前
|
Java 调度 Maven
【分布式任务调度平台 XXL-JOB 急速入门】从零开始将 XXL-JOB 接入到自己的项目(下)
【分布式任务调度平台 XXL-JOB 急速入门】从零开始将 XXL-JOB 接入到自己的项目(下)
235 0
|
3月前
|
NoSQL Java 应用服务中间件
大厂面试必备:如何轻松实现分布式Session管理?
这篇文章介绍三种分布式Session的实现方案:基于JWT的Token、基于Tomcat的Redis和基于Spring的Redis。JWT方案通过生成Token存储用户信息,实现无状态、可扩展的会话管理,但可能增加请求负载且数据安全性较低。Tomcat与Redis结合,通过配置Tomcat和Redis,实现Session集中管理和高性能存储,但配置相对复杂。Spring整合Redis适用于SpringBoot和SpringCloud项目,集成方便,扩展性强,但同样依赖外部Redis服务。每种方法有其优缺点,适用场景不同。作者小米是一个技术爱好者,欢迎关注其微信公众号“软件求生”获取更多技术内容
170 4
|
1月前
|
资源调度 Java 调度
项目环境测试问题之Schedulerx2.0通过分布式分片任务解决单机计算瓶颈如何解决
项目环境测试问题之Schedulerx2.0通过分布式分片任务解决单机计算瓶颈如何解决
项目环境测试问题之Schedulerx2.0通过分布式分片任务解决单机计算瓶颈如何解决
|
2月前
|
负载均衡 监控 搜索推荐
面试题ES问题之Solr和Elasticsearch在分布式管理上如何解决
面试题ES问题之Solr和Elasticsearch在分布式管理上如何解决
28 1
|
1月前
|
存储 缓存 开发框架
看看 Asp.net core Webapi 项目如何优雅地使用分布式缓存
看看 Asp.net core Webapi 项目如何优雅地使用分布式缓存
|
4月前
|
缓存 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
83 0
|
4月前
|
SpringCloudAlibaba Java 持续交付
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
374 0
|
2月前
|
SQL NoSQL Java
如何在Java项目中实现分布式锁
如何在Java项目中实现分布式锁
|
2月前
|
消息中间件 Java 中间件
如何在Java项目中实现分布式事务管理
如何在Java项目中实现分布式事务管理