Spring Boot第一个web在浏览器输出Hello

开始第一个Spring Boot,在web浏览器输出Hello,感受快速开发。

1、建立Maven项目,pom.xml文件代码如下:

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

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

2、编写运行代码

@RestController
@EnableAutoConfiguration
public class DemoApplication {

    @RequestMapping("/")
    String home() {
        return "Hello World!(世界 你好)";
    }

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

}

3、运行2代码后,在浏览器输入localhost:8080

浏览器显示内容(支持中文哦):Hello World!(世界 你好)

发布了5 篇原创文章 · 获赞 1 · 访问量 349

猜你喜欢

转载自blog.csdn.net/onion101325/article/details/104323153