SpringBoot2-01

时间:2021-02-22 12:18:59   收藏:0   阅读:0

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方法

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!