入门案例(hello-springBoot)

入门案例(hello-springBoot)

系统要求

Java 8+

Maven 3.6.6+

创建Maven项目工程

引入 pom.xml 依赖
    <!--1.导入父工程-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
    </parent>

    <!--2.导入springBoot的Web场景-->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
    </dependencies>
创建主程序 MainApplication 类
package com.xiang;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * Created by IntelliJ IDEA.
 * User: xiang
 * Date: 2021/10/12 10:10
 */
@SpringBootApplication
public class MainApplication {
    public static void main(String[] args) {
        SpringApplication.run(MainApplication.class, args);
    }
}

编写业务 HomeController 类
package com.xiang.controller;

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

/**
 * Created by IntelliJ IDEA.
 * User: xiang
 * Date: 2021/10/12 10:11
 */
@RestController
public class HomeController {
    @RequestMapping("/hello")
    public String Hello() {
//        return "Hello SpringBoot";
        return "<h1 style='color:red'>Hello SpringBoot<h1>";
    }
}

运行

posted @ 2021-10-12 12:44  阿向向  阅读(33)  评论(0编辑  收藏  举报