基于 SpringBoot+Mybatis+Redis+RabbitMQ 秒杀系统
项目启动说明
1、启动前,请配置 application.properties 中相关redis、mysql、rabbitmq地址。
2、登录地址: http://localhost:8888/page/login.
3、商品秒杀列表地址: http://localhost:8888/goods/list.
其它说明
1)、页面缓存、商品详情静态化、订单静态化(感兴趣可以把所有页面都做静态化)
2)、加入消息队列RabbitMQ,对秒杀接口进行优化。
3)、隐藏秒杀接口地址
4)、接口限流防刷
5)、解决超卖问题
页面截图
登录页
商品列表情页
图片:
controller
package cn.hfbin.seckill.controller;
import cn.hfbin.seckill.bo.GoodsBo;
import cn.hfbin.seckill.common.Const;
import cn.hfbin.seckill.entity.User;
import cn.hfbin.seckill.redis.GoodsKey;
import cn.hfbin.seckill.redis.RedisService;
import cn.hfbin.seckill.redis.UserKey;
import cn.hfbin.seckill.result.CodeMsg;
import cn.hfbin.seckill.result.Result;
import cn.hfbin.seckill.service.SeckillGoodsService;
import cn.hfbin.seckill.util.CookieUtil;
import cn.hfbin.seckill.vo.GoodsDetailVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.thymeleaf.spring4.context.SpringWebContext;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
@Controller
@RequestMapping("/goods")
public class GoodsController {
@Autowired
RedisService redisService;
@Autowired
SeckillGoodsService seckillGoodsService;
@Autowired
ThymeleafViewResolver thymeleafViewResolver;
@Autowired
ApplicationContext applicationContext;
@RequestMapping("/list")
@ResponseBody
public String list(Model model, HttpServletRequest request, HttpServletResponse response) {
//修改前
/* List<GoodsBo> goodsList = seckillGoodsService.getSeckillGoodsList();