时间:2021-05-19
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配置#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集成开发实现商场秒杀功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例为大家分享了springboot集成redis实现简单秒杀系统的具体代码,供大家参考,具体内容如下项目是有地址的,我会放到文章的最后面1.直接servi
springboot对kafka的client很好的实现了集成,使用非常方便,本文也实现了一个在springboot中实现操作kafka的demo。1.POM配
SpringBoot与Quartz集成实现分布式定时任务集群直接贴代码POM
基于springboot开发的微服务应用,与MyBatis如何集成?集成方法可行的方法有:1.基于XML或者JavaConfig,构建必需的对象,配置MyBat
SpringBoot集成MyBatis在集成MyBatis前,我们先配置一个druid数据源。SpringBoot集成druiddruid有很多个配置选项,使用