1  新建一个maven工程;

2 导入SpringBoot相关的依赖,即修改pom.xml文件配置;

 1 <!--这是Spring Boot的父级依赖,这样当前的项目就是Spring Boot项目了。
 2         spring-boot-starter-parent 是一个特殊的starter,
 3       它用来提供相关的Maven默认依赖。使用它之后,常用的包依赖可以省去version标签。-->
 4     <parent>
 5         <groupId>org.springframework.boot</groupId>
 6         <artifactId>spring-boot-starter-parent</artifactId>
 7         <version>2.2.5.RELEASE</version>
 8         <relativePath/> <!-- lookup parent from repository -->
 9     </parent>
10      <!--web的场景,自动帮我们引入了web模块开发需要的相关jar包-->
11     <dependencies>
12         <dependency>
13             <groupId>org.springframework.boot</groupId>
14             <artifactId>spring-boot-starter-web</artifactId>
15         </dependency>
16     </dependencies>

3 编写一个主程序,启动SpringBoot应用

 1 package com.atguigu;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 
 6 @SpringBootApplication//来标注一个主程序类,说明这是一个SpringBoot应用
 7 public class HelloWorldMainApplication {
 8     public static void main(String[] args) {
 9         //spring主程序跑起来
10         SpringApplication.run(HelloWorldMainApplication.class,args);
11     }
12 }

4 编写相关的Controller,Service

package com.atguigu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello(){

        return "你好世界";
    }
}

5运行主程序测试

6 简化部署,修改pom.xml文件

<!--打包成一个可以执行的jar包-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

 

posted on 2020-03-09 22:54  识途老码  阅读(228)  评论(0编辑  收藏  举报