java秒杀系统

项目框架搭建

1. SpringBoot环境搭建
2. 集成Thymeleaf,RespBean
3. MyBatis

分布式会话

1. 用户登录
	a. 设计数据库
	b. 明文密码二次MD5加密(数据库中存储一次加密后密码)
	c. 参数校验+全局异常处理(RespBean)
2. 共享Session
	a. SpringSession
	b. Redis

功能开发

1. 商品列表
2. 商品详情
3. 秒杀
4. 订单详情

系统压测

1. JMeter
2. 自定义变量模拟多用户
3. JMeter命令行的使用
4. 正式压测
	a. 商品列表
	b. 秒杀

页面优化

1. 页面缓存+URL缓存+对象缓存(Redis)
2. 页面静态化,前后端分离(把静态页面直接缓存到用户的浏览器端,所需要的数据从服务端接口动态获取)
3. 静态资源优化
4. CDN优化(全称是Content Delivery Network,即内容分发网络,将网站的内容发布到最接近用户的网络边缘,使用户可以就近取得所需的内容)

接口优化

1. Redis预减库存减少数据库的访问
2. 内存标记减少Redis的访问(当redis中库存为0,在内存中把map对应goodsid的库存为空状态设置为true)
3. RabbitMQ异步下单
	a. SpringBoot整合RabbitMQ
	b. 交换机

安全优化

1. 秒杀接口地址隐藏(防止明文传输被直接获得接口,秒杀先跳转到获得商品地址接口的接口再转向真正接口)
2. 验证码(防止脚本)
3. 接口防刷(防止短时间多次连接接口)

依赖使用

  1. Lombok(通过注解的方式减少get,set方法,构造方法)
<dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.22</version>
            <optional>true</optional>
</dependency>
  1. thymeleaf(Thymeleaf是一个模板引擎,主要用于编写动态页面,把model中的数据渲染到html中,因此其语法主要是如何解析model中的数据)
 <dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-thymeleaf</artifactId>
 </dependency>
  1. validation(validation作为jQuery的一个插件用于表单验证,如手机号码校验)
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>
  1. AMQP(AMQP是一个进程间传递异步消息的网络协议,Broker使用的RabbitMQ,传数据时将数据转为json格式)
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java实现秒杀系统@Controller @RequestMapping("seckill")//url:/模块/资源/{id}/细分 /seckill/list public class SeckillController { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private SeckillService seckillService; @RequestMapping(value="/list",method = RequestMethod.GET) public String list(Model model){ //获取列表页 List list=seckillService.getSeckillList(); model.addAttribute("list",list); //list.jsp+model = ModelAndView return "list";//WEB-INF/jsp/"list".jsp } @RequestMapping(value = "/{seckillId}/detail",method = RequestMethod.GET) public String detail(@PathVariable("seckillId") Long seckillId, Model model){ if (seckillId == null){ return "redirect:/seckill/list"; } Seckill seckill = seckillService.getById(seckillId); if (seckill == null){ return "forward:/seckill/list"; } model.addAttribute("seckill",seckill); return "detail"; } //ajax json @RequestMapping(value = "/{seckillId}/exposer", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) @ResponseBody public SeckillResult exposer(@PathVariable("seckillId") Long seckillId){ SeckillResult result; try { Exposer exposer =seckillService.exportSeckillUrl(seckillId); result = new SeckillResult(true,exposer); } catch (Exception e) { logger.error(e.getMessage(),e); result = new SeckillResult(false,e.getMessage()); } return result; } @RequestMapping(value = "/{seckillId}/{md5}/execution", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"} ) @ResponseBody public SeckillResult execute(@PathVariable("seckillId")Long seckillId,

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值