码迷,mamicode.com
首页 > 编程语言 > 详细

SpringBoot构建电商秒杀项目

时间:2020-05-24 19:15:44      阅读:66      评论:0      收藏:0      [点我收藏+]

标签:for   http   spi   port   ppi   stc   下单   play   span   

  一、项目功能概述

电商秒杀需要完成的3个功能:

1.展示一个商品列表页面,我们可以从中看到可秒杀的商品列表

2.点击进入商品详情页,获取该商品的详细信息

3.秒杀时间开始后,点击进入下单确认页面,并支付成功

  二、基于SpringBoot进行项目环境搭建

步骤1:创建一个maven工程,使用quickStart骨架。

步骤2:在pom.xml导入SpringBoot相关依赖。

技术图片
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5   <modelVersion>4.0.0</modelVersion>
 6 
 7   <groupId>org.example</groupId>
 8   <artifactId>Spike</artifactId>
 9   <version>1.0-SNAPSHOT</version>
10 
11   <name>Spike</name>
12   <!-- FIXME change it to the project‘s website -->
13   <url>http://www.example.com</url>
14 
15  <parent>
16    <groupId>org.springframework.boot</groupId>
17    <artifactId>spring-boot-starter-parent</artifactId>
18    <version>2.0.5.RELEASE</version>
19  </parent>
20 
21   <properties>
22     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23     <maven.compiler.source>1.8</maven.compiler.source>
24     <maven.compiler.target>1.8</maven.compiler.target>
25   </properties>
26 
27   <dependencies>
28     <dependency>
29       <groupId>org.springframework.boot</groupId>
30       <artifactId>spring-boot-starter-web</artifactId>
31     </dependency>
32     <dependency>
33       <groupId>junit</groupId>
34       <artifactId>junit</artifactId>
35       <version>4.11</version>
36       <scope>test</scope>
37     </dependency>
38   </dependencies>
39 
40   <build>
41     <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
42       <plugins>
43         <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
44         <plugin>
45           <artifactId>maven-clean-plugin</artifactId>
46           <version>3.1.0</version>
47         </plugin>
48         <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
49         <plugin>
50           <artifactId>maven-resources-plugin</artifactId>
51           <version>3.0.2</version>
52         </plugin>
53         <plugin>
54           <artifactId>maven-compiler-plugin</artifactId>
55           <version>3.8.0</version>
56         </plugin>
57         <plugin>
58           <artifactId>maven-surefire-plugin</artifactId>
59           <version>2.22.1</version>
60         </plugin>
61         <plugin>
62           <artifactId>maven-jar-plugin</artifactId>
63           <version>3.0.2</version>
64         </plugin>
65         <plugin>
66           <artifactId>maven-install-plugin</artifactId>
67           <version>2.5.2</version>
68         </plugin>
69         <plugin>
70           <artifactId>maven-deploy-plugin</artifactId>
71           <version>2.8.2</version>
72         </plugin>
73         <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
74         <plugin>
75           <artifactId>maven-site-plugin</artifactId>
76           <version>3.7.1</version>
77         </plugin>
78         <plugin>
79           <artifactId>maven-project-info-reports-plugin</artifactId>
80           <version>3.0.0</version>
81         </plugin>
82       </plugins>
83     </pluginManagement>
84   </build>
85 </project>
pom.xml

步骤3:在main/java/app中,我们对SpringBoot和SpringMVC进行简单的配置工作。掌握这几个注解的作用。

 1 package org.example;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
 5 import org.springframework.web.bind.annotation.RequestMapping;
 6 import org.springframework.web.bind.annotation.RestController;
 7 
 8 //SpringBoot会帮我们启动tomcat,并加载默认配置
 9 @EnableAutoConfiguration
10 //SpringMVC相关配置
11 @RestController
12 public class App {
13     @RequestMapping("/")
14     public String home(){
15         //网页中输出
16         return "Hello World!";
17     }
18     public static void main( String[] args ){
19         //控制台输出
20         System.out.println( "Hello World!" );
21         SpringApplication.run(App.class,args);
22     }
23 }

运行结果:

用浏览器打开http://localhost:8080/,我们可以看到页面上输出:Hello World!

同时,控制台也输出了Hello World!,以及一些Spring相关的信息。

SpringBoot构建电商秒杀项目

标签:for   http   spi   port   ppi   stc   下单   play   span   

原文地址:https://www.cnblogs.com/augenstern/p/12952167.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!