您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“如何使用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集成開發實現商場秒殺功能”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。