Spring Boot入门

 

 

一、新建一个Meven项目,编写pom.xml,添加必要的依赖。

xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>

    <groupId>com.examplegroupId>
    <artifactId>myprojectartifactId>
    <version>0.0.1-SNAPSHOTversion>

    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.3.1.RELEASEversion>
    parent>

    <description/>
    <developers>
        <developer/>
    developers>
    <licenses>
        <license/>
    licenses>
    <scm>
        <url/>
    scm>
    <url/>

    

project>

二、创建一个Java文件,编写代码,内容如下。

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class Example {

    @RequestMapping("/")
    String home() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(Example.class, args);
    }

}

三、运行main方法。

四、打开浏览器,输入http://localhost:8080/,应该会看到浏览器输出:Hello World!

Spring Boot入门_第1张图片

 

相关学习资料

springboot官网:https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/index.html

b站:https://www.bilibili.com/video/BV1Et411Y7tQ?from=search&seid=3537728523864607960

 

你可能感兴趣的:(Spring Boot入门)