SpringBoot2-01

Spring Boot2入门

1.使用idea新建一个名为boot的Maven工程。
2.点击右下角的“Enable Auto-Import”选项,idea将会自动下载相关的依赖包。

3.点击boot目录下的pom.xml文件,引入以下依赖:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

4.手动创建主程序类,类名默认为MainApplication。

package com.per.boot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 *使用 @SpringBootApplication修饰该类表示这是一个SpringBoot应用
 */
@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class,args);
    }
}

5.编写业务

package com.per.boot.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorld {

    @RequestMapping("/hello")
    public String handle(){
        return "Hello, Spring Boot2!";
    }
}

6.测试:直接运行main方法

原文地址:https://www.cnblogs.com/daydayupup/p/14423956.html