springboot集成实现秒杀
程序员文章站
2022-08-11 19:21:29
springboot集成开发实现商场秒杀 加入主要依赖 org.springframework.boot spring-boot-starter-thymeleaf
本人免费整理了java高级资料,涵盖了java、redis、mongodb、mysql、zookeeper、spring cloud、dubbo高并发分布式等教程,一共30g,需要自己领取。
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:数据传输对象
秒杀系统逻辑
实现技术点
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
————————————————
本人免费整理了java高级资料,涵盖了java、redis、mongodb、mysql、zookeeper、spring cloud、dubbo高并发分布式等教程,一共30g,需要自己领取。
传送门:https://mp.weixin.qq.com/s/osb-bol6w-zltstttkqmpq
上一篇: smarty模板引擎之分配数据类型
下一篇: 11工作流当中的角色组
推荐阅读
-
SpringBoot集成JPA
-
在wamp集成环境下升级php版本(实现方法)_php技巧
-
SpringBoot + Shiro 实现微博登录
-
SpringBoot集成shiro,MyRealm中无法@Autowired注入Service的问题
-
SpringBoot+Vue.js实现前后端分离的文件上传功能
-
浅谈Java(SpringBoot)基于zookeeper的分布式锁实现
-
springboot实现添加邮件发送及压缩功能
-
SpringBoot与Quartz集成实现分布式定时任务集群的代码实例
-
springboot集成rabbitMQ之对象传输的方法
-
Springboot2.X集成redis集群(Lettuce)连接的方法