springboot集成开发实现商场秒杀功能

作者:一染墨清尘 时间:2022-06-23 11:05:27 

springboot集成开发实现商场秒杀

加入主要依赖


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- alibaba的druid数据库连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
<!-- redis客服端-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.38</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>

秒杀项目主要目录构架

1.java目录

config 所有的配置信息
controller
exception 所有业务异常
mapper
service
rabbitmq
redis redis缓存
validator 后端校验
bean:数据传输层包括:mysql以及redis
util:工具包
dto:数据传输对象

秒杀系统逻辑

springboot集成开发实现商场秒杀功能

实现技术点

1.MD5

实现用户的密码为加密在保存到数据库之前

2.全局异常统一处理

通过拦截所有异常,对各种异常进行相应的处理

3.页面缓存

通过手动渲染的html页面缓存到redis中


WebContext ctx = new WebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap());
html = thymeleafViewResolver.getTemplateEngine().process("goods_detail", ctx);

4.解决了超买


application.properties配置
#thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.check-template=true
spring.thymeleaf.check-template-location=true
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.enabled=true
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=HTML5
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
# mybatis
mybatis.type-aliases-package=com.jesper.seckill.mapper
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100
mybatis.configuration.default-statement-timeout=3000
mybatis.mapperLocations = classpath:com/jesper/seckill/mapper/*.xml
# druid
spring.datasource.url=jdbc:mysql://localhost:3306/seckill?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.filters=stat
spring.datasource.maxActive=1000
spring.datasource.initialSize=100
spring.datasource.maxWait=60000
spring.datasource.minIdle=500
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=select 'x'
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
spring.datasource.poolPreparedStatements=true
spring.datasource.maxOpenPreparedStatements=20
#redis
redis.host=127.0.0.1
redis.port=6379
redis.timeout=10
redis.poolMaxTotal=1000
redis.poolMaxIdle=500
redis.poolMaxWait=500
#static
spring.resources.add-mappings=true
spring.resources.cache.period= 3600
spring.resources.chain.cache=true
spring.resources.chain.enabled=true
spring.resources.chain.compressed=true
spring.resources.chain.html-application-cache=true
spring.resources.static-locations=classpath:/static/
#rabbitmq
spring.rabbitmq.host=127.0.0.1
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.virtual-host=/
spring.rabbitmq.listener.simple.concurrency= 10
spring.rabbitmq.listener.simple.max-concurrency= 10
spring.rabbitmq.listener.simple.prefetch= 1
spring.rabbitmq.listener.simple.auto-startup=true
spring.rabbitmq.listener.simple.default-requeue-rejected= true
spring.rabbitmq.template.retry.enabled=true
spring.rabbitmq.template.retry.initial-interval=1000
spring.rabbitmq.template.retry.max-attempts=3
spring.rabbitmq.template.retry.max-interval=10000
spring.rabbitmq.template.retry.multiplier=1.0

总结

以上所述是小编给大家介绍的springboot集成开发实现商场秒杀功能网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

来源:https://blog.csdn.net/qq_43619512/article/details/103687243

标签:spring,boot,集成,秒杀
0
投稿

猜你喜欢

  • 浅谈Java关闭线程池shutdown和shutdownNow的区别

    2021-12-28 04:43:44
  • Android利用Sensor(传感器)实现指南针小功能

    2021-12-27 14:22:36
  • 简单聊聊C#字符串构建利器StringBuilder

    2022-07-15 12:49:44
  • 详解Java线程同步器CountDownLatch

    2023-08-23 18:42:39
  • 一文带你搞懂Java8的LocalDateTime

    2023-11-10 02:02:22
  • 解析Spring Mvc Long类型精度丢失问题

    2021-11-06 12:27:37
  • Android制作漂亮自适布局键盘的方法

    2022-08-04 09:14:53
  • springCloud config本地配置操作

    2023-01-13 11:07:56
  • android调用国家气象局天气预报接口json数据格式解释

    2022-09-16 21:08:24
  • spring boot使用thymeleaf跳转页面实例代码

    2021-09-14 09:46:16
  • Java基本数据类型族谱与易错点梳理解析

    2021-08-18 10:20:27
  • Java使用原型模式展现每日生活应用案例详解

    2023-03-08 04:27:08
  • Android延迟实现的几种解决方法及原理分析

    2023-10-24 18:07:15
  • Java中的静态内部类详解及代码示例

    2021-11-25 08:50:00
  • Java动态代 理分析及简单实例

    2023-11-24 21:14:56
  • Android ViewPager无限循环滑动并可自动滚动完整实例

    2022-09-09 18:26:55
  • springMVC实现前台带进度条文件上传的示例代码

    2021-09-15 17:24:44
  • Java异常处理之try...catch...finally详解

    2023-09-17 05:38:24
  • Java实现线程安全单例模式的五种方式的示例代码

    2023-09-26 16:41:23
  • Java基础之二叉搜索树的基本操作

    2023-07-08 10:07:07
  • asp之家 软件编程 m.aspxhome.com