/**
* 当前秒杀的商品
* @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;
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |