1. 构建工程

a. 地址:http://start.spring.io/

b. 填写Group、Artifact

c. 生成工程、下载、解压

2. 项目结构

SpringBoot helloworld

3. 添加controller内容

package com.jihite.helloworld.controller;

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

@RestController
public class HelloController {
    @RequestMapping("/hello")
    public String index() {
        return "Hello World~";
    }
}

4. pom.xml

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

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

5. 运行main函数

请求:http://localhost:8080/hello

返回:Hello World~

 

相关文章:

  • 2021-12-14
  • 2021-12-24
  • 2021-10-18
  • 2021-07-05
  • 2021-04-16
  • 2020-05-30
  • 2021-12-22
猜你喜欢
  • 2021-06-01
  • 2017-12-05
  • 2019-09-12
  • 2021-08-10
  • 2021-04-24
相关资源
相似解决方案