Spring-boot-hello-world

Spring-boot-hello-world

版本

  • jdk1.8
  • spring boot 2.3.0

什么是spring-boot?

  • 概念
    spring-boot是简化spring开发的J2EE的一站式解决方案,它并不是新的框架,而是默认配置集成了框架的使用方式,从而使我们的开发配置变得简单。
  • 优势
    内置tomcat 让我们部署不用基于war包形式部署
    通过加载各种starter启动器,让我们开发的时候采用默认配置,同时它维护了maven依赖关系简化了maven配置。
    类配置代替了xml配置,让开发和理解更方便
  • 创建项目

image
image
image

hello word

  • pom配置
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  • 书写controller
@RestController
public class HelloWorldController {

    @RequestMapping("/hello-world")
    public String helloWorld() {
        return "Hello World";
    }
}
  • 请求
    http://localhost:8080/hello 可以看到 “Hello World”

拓展

  • 配置可以写在application.yml 或者 application.properties 其中 yml优先加载
  • 默认端口是8080
server:
#  启动端口
  port: 8000
#  context path 前缀
  servlet:
    context-path: /api

猜你喜欢

转载自blog.csdn.net/m0_47878423/article/details/106159815