A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区
传智教育官网黑马程序员官网
只需一步,快速开始
谷粒姐姐
黑马粉丝团
黑马币:447
帖子:57327
精华:0
© 谷粒姐姐 黑马粉丝团 / 2018-11-1 17:06 / 1049 人查看 / 0 人回复 / 1 人收藏 转载请遵从CC协议 禁止商业使用本文
/** * 当前秒杀的商品 * @return */ @RequestMapping("/findList") public List<TbSeckillGoods> findList(){ return seckillGoodsService.findList(); }
//服务层 app.service('seckillGoodsService',function($http){ //读取列表数据绑定到表单中 this.findList=function(){ return $http.get('seckillGoods/findList.do'); } });
//控制层 app.controller('seckillGoodsController' ,function($scope,seckillGoodsService){ //读取列表数据绑定到表单中 $scope.findList=function(){ seckillGoodsService.findList().success( function(response){ $scope.list=response; } ); } });
<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/seckillGoodsService.js"> </script> <script src="js/controller/seckillGoodsController.js"> </script>
<body ng-app="pinyougou" ng-controller="seckillGoodsController" ng-init="findList()">
<li class="seckill-item" ng-repeat="pojo in list"> <div class="pic"> <img src="{{pojo.smallPic}}" width="290px" height="290px" alt=''> </div> <div class="intro"><span>{{pojo.title}}</span></div> <div class='price'><b class='sec-price'>¥{{pojo.costPrice}}</b><b class='ever-price'>¥{{pojo.price}}</b></div> <div class='num'> <div>已售{{ ((pojo.num-pojo.stockCount)/pojo.num*100).toFixed(0) }}%</div> <div class='progress'> <div class='sui-progress progress-danger'><span style='width: {{ ((pojo.num-pojo.stockCount)/pojo.num*100).toFixed(0) }}%;' class='bar'></span></div> </div> <div>剩余<b class='owned'>{{pojo.stockCount}}</b>件</div> </div> <a class='sui-btn btn-block btn-buy' href='seckill-item.html#?id={{pojo.id}}' target='_blank'>立即抢购</a> </li>
@Autowired private RedisTemplate redisTemplate; @Override public List<TbSeckillGoods> findList() { //获取秒杀商品列表 List<TbSeckillGoods> seckillGoodsList = redisTemplate.boundHashOps("seckillGoods").values(); if(seckillGoodsList==null || seckillGoodsList.size()==0){ TbSeckillGoodsExample example=new TbSeckillGoodsExample(); Criteria criteria = example.createCriteria(); criteria.andStatusEqualTo("1");//审核通过 criteria.andStockCountGreaterThan(0);//剩余库存大于 0 criteria.andStartTimeLessThanOrEqualTo(new Date());//开始时间小于等于当前 时间 criteria.andEndTimeGreaterThan(new Date());//结束时间大于当前时间 seckillGoodsList= seckillGoodsMapper.selectByExample(example); //将商品列表装入缓存 System.out.println("将秒杀商品列表装入缓存"); for(TbSeckillGoods seckillGoods:seckillGoodsList){ redisTemplate.boundHashOps("seckillGoods").put(seckillGoods.getId(), seckillGoods); } } return seckillGoodsList; }