如何使用springboot集成开发实现商场秒杀功能

发布时间:2021-09-28 11:17:11 作者:小新
来源:亿速云 阅读:108

这篇文章主要为大家展示了“如何使用springboot集成开发实现商场秒杀功能”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何使用springboot集成开发实现商场秒杀功能”这篇文章吧。

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 所有的配置信息controllerexception 所有业务异常mapperservicerabbitmqredis redis缓存validator 后端校验bean:数据传输层包括:mysql以及redisutil:工具包dto:数据传输对象

秒杀系统逻辑

实现技术点

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

以上是“如何使用springboot集成开发实现商场秒杀功能”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. springboot集成html中分页功能如何实现
  2. SpringBoot怎么集成PageHelper实现分页功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

springboot

上一篇:Java9中StreamCollectors新增功能有哪些

下一篇:有哪些有用的Shell脚本

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》